Skip to content

kylef-archive/GoReactive

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages