SkillAgentSearch skills...

GoReactive

Go library for Functional Reactive Programming, a library for representing and consuming asyncronous data streams with Observables

Install / Use

/learn @kylef-archive/GoReactive
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

GoReactive

Build Status

GoReactive is a Go library for Function Reactive Programming, a library for representing and consuming asyncronous data streams with Observables.

Usage

Observables

At it's simplest form, an Observable is an interface which allows you to subscribe to events, the next value, the completion or the failure.

observable.Subscribe(
  func(value interface{}) { /* a new value has been sent */ },
  func() { /* the stream has completed */ },
  func(err error) { /* the stream has errored */ }
)

Transforming an Observable

Using Map, you can transform an Observables next values. For example, we can use the following to create a new Observable from an Observable of integers by multiplying their value.

transformedObservable := Map(observable, func(value interface{}) interface{} {
  return value.(int) * 2
})

Filtering an Observable

Using Filter and Exclude you can filter or exclude next values from an Observable. We can use the following to create a new Observable from an Observable of integers, filtering for all even numbers.

filteredObservable := Filter(observable, func(value interface{}) bool {
  return (value.(int) % 2) == 0
})

Subject

A Subject is an interface for creating Observables, a Subject contains functions to emit new values into your Observable.

subject.SendNext("Kyle")
subject.SendNext("Katie")
subject.SendCompletion()
subject.SendError(err)

Creating a new subject using NewObservable

NewObservable is a function for creating an Observable, which when subscribed, it will call a callback allowing you to send events using a Subject.

observable := NewObservable(func(subject *Subject) Disposable {
  subject.SendNext("Hello, my subscriber.")
  return nil
})

License

GoReactive is licensed under the BSD license. See LICENSE for more info.

View on GitHub
GitHub Stars14
CategoryDevelopment
Updated6y ago
Forks1

Languages

Go

Security Score

75/100

Audited on Aug 18, 2019

No findings