Popularity
0.5
Declining
Activity
1.3
Declining
4
1
0

Description

A simplified version of RxJs for golang. (Easier than RxGo)

Programming language: Go
License: GNU Affero General Public License v3.0
Tags: Utilities     Publish     Subscribe     Pubsub     Golang    

Reactive alternatives and similar packages

Based on the "Utilities" category.
Alternatively, view Reactive alternatives based on common mentions on social networks and blogs.

Do you think we are missing an alternative of Reactive or a related project?

Add another 'Utilities' Package

README

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