Appendix C. Comparison of FRP systems
The tables in this appendix relate the primitives named in this book to each system’s API. They’re not necessarily directly equivalent, but you will be able to tell where in that system’s API to start looking. If a field is blank, there is no equivalent.
Variable names give clues, mainly these:
- s—Stream
- c—Cell
- i—Initial value
- h—Handler
- a—Value
Table C.1. Cheat sheet for Sodium, RxJS, and Bacon.JS
Primitive |
Sodium (Java) |
RxJS (JS) |
Bacon.JS (JS) |
---|---|---|---|
Stream | Stream | Rx.Observable | EventStream |
Cell | Cell | Rx.BehaviorSubject | Property |
never | new Stream() | Rx.Observable.of() | Bacon.never() |
constant | new Cell(i) | Rx.Observable.of(i) | Bacon.constant(i) |
map (S) | s.map(f) | s.map(f) | e.map(f) |
map (C) | c.map(f) | c.map(f) | p.map(f) |
merge | s1.orElse(s2) s1.merge(s2) | s1.merge(s2) | s1.merge(s2) |
hold | s.hold(i) | var c = new Rx.BehaviorSubject(i); s.subscribe(c); | s.toProperty(i) |
snapshot | s.snapshot(c, f) | s.withLatestFrom(c, f) | c.sampledBy(s, f) |
filter | s.filter(f) | s.filter(f) | s.filter(f) |
lift | c1.lift(c2, f) | c1.combineLatest(c2, f) | c1.combine(c2, f) |
sample | c.sample() | ||
switch | Cell.switchS() Cell.switchC() | s.flatMapLatest(f) | s.flatMapLatest(f) |
accum | s.accum(i, f) | s.scan(i, f) | s.scan(i, f) |
listen | s.listen(h) c.listen(h) | s.subscribe(h) | s.listen(h) p.listen(h) |
send | StreamSink / ss.send(a) CellSink / cs.send(a) | Rx.Observable.create(f) | new Bacon.EventStream(f) |