Reactive programming utilities for go, implmenting with go channels. Inspired by ReactiveX.
go get -u github.com/vagase/reactive-channel
inChan := From([]interface{}{1, 2, 2, 3, 3, 5})
outChan := Distinct(inChan)
outChan will emit: 1, 2, 3, 5
inChan := From([]interface{}{1, 2, 3, 4})
outChan := Filter(inChan, func(i interface{}) bool {
num := i.(int)
return num%2 == 0
})
outChan will emit: 2 4
// 1, 2, 3, 4
inChan1 := IntervalRange(1, 4, time.Millisecond*30, 0)
// a, b
inChan2 := Map(IntervalRange(0, 2, time.Millisecond*50, 0), func(i interface{}) interface{} {
return string(97 + i.(int))
})
outChan := Map(CombineLatest(inChan1, inChan2), func(i interface{}) interface{} {
values := i.([]interface{})
return strconv.Itoa(values[0].(int)) + values[1].(string)
})
outChan will emit: "1a", "2a", "3a", "3b", "4b"
inChan := IntervalRange(0, 4, 40*time.Millisecond, 0)
outChan := Debounce(inChan, time.Millisecond*100)
outChan will emit: 0, 3
reactive-channel implements most useful ReactiveX operators, checkout full api list here.
- From
- Interval
- IntervalRange
- Range
- Repeat
- Just
- Timer
- Map
- Reduce
- Filter
- Merge
- Subscribe
- Buffer
- FlatMap
- GroupBy
- Debounce
- Distinct
- ElementAt
- First
- Last
- IgnoreElements
- Sample
- Skip
- SkipLast
- Take
- TakeLast
- CombineLatest
- StartWith
- Switch
- Zip
- Delay
- TimeInterval
- Timeout
- Timestamp
- All
- Contains
- Amb
- DefaultIfEmpty
- SequenceEqual
- SkipUntil
- SkipWhile
- TakeUntil
- TakeWhile
- Sum
- Average
- Count
- Min
- Max
- Concat
- IsEmpty
- WindowWithCount
MIT Licence © vagase