Reactive Extensions for Golang with pipe support

Reactive GoDoc Go Report Card Codacy Badge

My attempt on creating a simple RxJs clone

Features

  • Observables
    • Multi-Type support
  • Subjects
    • Subject
    • ReplaySubject
  • Pipes
    • Take
    • TakeEvery
    • Skip
    • SkipEvery

Examples

Simple Subject

package main

import (
    "github.com/infinytum/reactive"
    "fmt"
)

func main() {
	subject := reactive.NewSubject()
	subject.Subscribe(subHandler)
	subject.Next(1)
	subject.Next(2)
	subject.Next(3)
	subject.Next(4)
}

func subHandler(a int) {
	fmt.Println(a)
}

Output

$ go run main.go
1
2
3
4

Replay Subject

package main

import (
    "github.com/infinytum/reactive"
    "fmt"
)

func main() {
    subject := reactive.NewReplaySubject()
    subject.Next(1)
    subject.Next(2)
    subject.Next(3)
    subject.Subscribe(subHandler)
    subject.Next(4)
}

func subHandler(a int) {
	fmt.Println(a)
}

Output

$ go run main.go
3
4

Multi-Type support

package main

import (
    "github.com/infinytum/reactive"
    "fmt"
)

func main() {
	subject := reactive.NewSubject()

	subject.Subscribe(intHandler)
	subject.Subscribe(stringHandler)

	subject.Next(2)
	subject.Next("Hello")
	subject.Next("World")
	subject.Next(4)
	subject.Next(nil)
}

func intHandler(a int) {
	fmt.Print("Int Handler: ")
	fmt.Println(a)
}

func stringHandler(a string) {
	fmt.Print("String Handler: ")
	fmt.Println(a)
}

Output

Int Handler: 2
String Handler: Hello
String Handler: World
Int Handler: 4
Int Handler: 0
String Handler:

Take Pipe

package main

import (
    "github.com/infinytum/reactive"
    "fmt"
)

func main() {
    subject := reactive.NewReplaySubject()
    subject.Pipe(reactive.Take(2)).Subscribe(subHandler)
    subject.Next(1)
    subject.Next(2)
    subject.Next(3)
    subject.Next(4)
}

func subHandler(a int) {
	fmt.Println(a)
}

Output

$ go run main.go
1
2

TakeEvery Pipe

package main

import (
    "github.com/infinytum/reactive"
    "fmt"
)

func main() {
    subject := reactive.NewReplaySubject()
    subject.Pipe(reactive.TakeEvery(2)).Subscribe(subHandler)
    subject.Next(1)
    subject.Next(2)
    subject.Next(3)
    subject.Next(4)
}

func subHandler(a int) {
	fmt.Println(a)
}

Output

$ go run main.go
2
4

Skip Pipe

package main

import (
    "github.com/infinytum/reactive"
    "fmt"
)

func main() {
    subject := reactive.NewReplaySubject()
    subject.Pipe(reactive.Skip(2)).Subscribe(subHandler)
    subject.Next(1)
    subject.Next(2)
    subject.Next(3)
    subject.Next(4)
}

func subHandler(a int) {
	fmt.Println(a)
}

Output

$ go run main.go
3
4

SkipEvery Pipe

package main

import (
    "github.com/infinytum/reactive"
    "fmt"
)

func main() {
    subject := reactive.NewReplaySubject()
    subject.Pipe(reactive.SkipEvery(2)).Subscribe(subHandler)
    subject.Next(1)
    subject.Next(2)
    subject.Next(3)
    subject.Next(4)
}

func subHandler(a int) {
	fmt.Println(a)
}

Output

$ go run main.go
1
3
Owner
Nila the Dragon
Young programmer (22) working on private projects / trying out new technologies in his spare time. #GoLang #Angular #gRPC
Nila the Dragon
Similar Resources

Privacy important, fast, recursive dns resolver server with dnssec support

Privacy important, fast, recursive dns resolver server with dnssec support

🚀 Privacy important, fast, recursive dns resolver server with dnssec support Installation go get github.com/semihalev/sdns Pre-build Binaries Downloa

Dec 26, 2022

rpc/v2 support for JSON-RPC 2.0 Specification.

rpc rpc/v2 support for JSON-RPC 2.0 Specification. gorilla/rpc is a foundation for RPC over HTTP services, providing access to the exported methods of

Jul 4, 2021

Support for Unix domain sockets in Go HTTP clients

unixtransport This package adds support for Unix domain sockets in Go HTTP clients. t := &http.Transport{...} unixtransport.Register(t) client := &h

Dec 21, 2022

High-performance, non-blocking, event-driven, easy-to-use networking framework written in Go, support tls/http1.x/websocket.

High-performance, non-blocking, event-driven, easy-to-use networking framework written in Go, support tls/http1.x/websocket.

Jan 8, 2023

Designed to support DNS brute-forcing with a minimal number of network connections

Fast Use of DNS Resolvers Designed to support DNS brute-forcing with a minimal number of network connections. Installation go get -v -u github.com/caf

Dec 8, 2022

Service registration and discovery, support etcd, zookeeper, consul, etc.

discox 支持类型 zookeeper etcd consul 示例 zookeeper server package main import ( "fmt" "github.com/goeasya/discox" "os" ) func main() { cfg := discox

Aug 31, 2022

WIP protobuf support for Gleam ✨

gleam_pb WIP protobuf support for Gleam ✨ Progress Gleam Type generation custom functions that better handle default values stop including unnecessary

Feb 26, 2022

a tcp framework which support pub/sub and request/reply

支持 事件订阅/请求回应 的的TCP通讯框架 源于 zinx 的业务定制版本 TCP 通讯框架 特点 服务端/客户端均支持订阅事件通讯. 服务端支持 Broadcast 方式发送信息到客户端. 客户端均支持 Request/Reply 方式与服务端通讯 服务端用多个worker去处理客户端的请求 目

Oct 9, 2021

DeSo is a blockchain built from the ground up to support a fully-featured social network

DeSo is a blockchain built from the ground up to support a fully-featured social network. Its architecture is similar to Bitcoin, only it supports complex social network data like profiles, posts, follows, creator coin transactions, and more.

Dec 22, 2022
Comments
  • Silently swallowed error

    Silently swallowed error

    https://github.com/infinytum/reactive/blob/c12d8413dd3d7e266111a1bdad36c396f4385c42/take.go

    Silently swallows errors and prints to console instead of passing or panicing.

  • Catch-all parameter is considered incompatible with multi-value calls

    Catch-all parameter is considered incompatible with multi-value calls

    Subscribing a method with the following signature

    func handler(args ...interface{}) {}
    

    Is not fired at all. I think to add a check for such catch-all.

ipx provides general purpose extensions to golang's IP functions in net package

ipx ipx is a library which provides a set of extensions on go's standart IP functions in net package. compability with net package ipx is fully compat

May 24, 2021
Openldap (LDAP) binding for Golang (go) ; no more support ; you may have a look at https://github.com/go-ldap/ldap

OpenLDAP this is Openldap binding in GO language. I don't work any more with golang, so, please fork this project. Installation : Installation is easy

Mar 4, 2021
Ping library for Golang with multi-host support

pingo Fast and lightweight ping library for Golang with multi-host support. Features ICMP sockets: UDP port 0 means "let the kernel pick a free number

Nov 9, 2022
🚀Gev is a lightweight, fast non-blocking TCP network library based on Reactor mode. Support custom protocols to quickly and easily build high-performance servers.
🚀Gev is a lightweight, fast non-blocking TCP network library based on Reactor mode. Support custom protocols to quickly and easily build high-performance servers.

gev 中文 | English gev is a lightweight, fast non-blocking TCP network library based on Reactor mode. Support custom protocols to quickly and easily bui

Jan 6, 2023
SFTP support for the go.crypto/ssh package

sftp The sftp package provides support for file system operations on remote ssh servers using the SFTP subsystem. It also implements an SFTP server fo

Jan 3, 2023
Package socket provides a low-level network connection type which integrates with Go's runtime network poller to provide asynchronous I/O and deadline support. MIT Licensed.

socket Package socket provides a low-level network connection type which integrates with Go's runtime network poller to provide asynchronous I/O and d

Dec 14, 2022
A Xray backend framework that can easily support many panels. 一个基于Xray的后端框架,支持V2ay,Trojan,Shadowsocks协议,极易扩展,支持多面板对接

XRayR A Xray backend framework that can easily support many panels. 一个基于Xray的后端框架,支持V2ay,Trojan,Shadowsocks协议,极易扩展,支持多面板对接。 如果您喜欢本项目,可以右上角点个star+watch

Jan 4, 2023
A tiny command line DNS client with support for UDP, DoT, DoH, and DoQ.
A tiny command line DNS client with support for UDP, DoT, DoH, and DoQ.

q A tiny command line DNS client with support for UDP, DoT, DoH, and DoQ. Usage q command line DNS client (https://github.com/natesales/q) Usage: q

Jan 4, 2023
SOCKS Protocol Version 5 Library in Go. Full TCP/UDP and IPv4/IPv6 support

socks5 中文 SOCKS Protocol Version 5 Library. Full TCP/UDP and IPv4/IPv6 support. Goals: KISS, less is more, small API, code is like the original protoc

Jan 8, 2023