Correcting two flaws with this leads to an interesting result:
1) no error handling, at all, anywhere, not just missing from the presentation, but not in the code. transduce just wraps reduce. FAIL!!!
2) the 'result' parameter unnecessarily pollutes the interface. reduce can be reduced to foreach (doseq) with state and be implemented like other tranducers that require state.
Correcting for these two errors:
a) the 0-arity init function is removed
b) the 1-arity completed function becomes 0-arity
c) the 2-arity reducing function becomes 1-arity
d) a 1-arity error function is added.
Since these functions cannot be distinguished by arity alone, we give them names: call the reducing function 'onNext', the error function 'onError', and the completed function 'onCompleted', and optionally, group the three functions into an object and voila, we have Rx Observers.
Hickey's twist here is composing Observers instead of Observables. Whether this buys you anything worthwhile is debatable.
Two derivations of Rx often accompany it's introduction:
1) Observable being the dual of Iterable
2) Observables being Promises with multiple return values.
Thanks to Hickey, we can add Observers being an abstraction from reduce/fold (along with it's many other names).
Correcting for these two errors: a) the 0-arity init function is removed b) the 1-arity completed function becomes 0-arity c) the 2-arity reducing function becomes 1-arity d) a 1-arity error function is added. Since these functions cannot be distinguished by arity alone, we give them names: call the reducing function 'onNext', the error function 'onError', and the completed function 'onCompleted', and optionally, group the three functions into an object and voila, we have Rx Observers.
Hickey's twist here is composing Observers instead of Observables. Whether this buys you anything worthwhile is debatable.
Two derivations of Rx often accompany it's introduction: 1) Observable being the dual of Iterable 2) Observables being Promises with multiple return values. Thanks to Hickey, we can add Observers being an abstraction from reduce/fold (along with it's many other names).