Redux in a single line of RxJS.

Redux in a single line of RxJS.

action$.scan(reducer, initstate).subscribe(renderer)

The scan() operator in RxJS is just like reduce() operator in most fuctional libraries except for one thing, it emits partial reductions continuously as a stream which you can subscribe to. This is applied to a stream of actions (actions$) and the reducer is a pure function which is applied to each action in turn with the signature.

(state, action) => newstate

The state is the “accumulator” of the reduction and scan() emits a stream of states as its output. The render object is an Observer which is like a listener with callbacks for next(value), error(err) and complete().

Another attempt to explain Haskell to the wilfully ignorant.

Another attempt to explain Haskell to the wilfully ignorant.

This post is an experiment I decided to attempt after conversations with Ben Lesh and some other folks. I will assume as little knowledge of Haskell as I possibly can here. Later we’ll talk about some tools we have in Haskell to make the pattern more conceptually compact.