jlongster / transducers.js

A small library for generalized transformation of data (inspired by Clojure's transducers)
BSD 2-Clause "Simplified" License
1.73k stars 54 forks source link

fix application of compose helper doc #32

Closed deepak1556 closed 9 years ago

deepak1556 commented 9 years ago
> var transform = t.compose(t.map(function (x) { return [x.length] }), t.cat)
undefined
> t.seq([[1,2,3], [34,5], [2,3,4,4]], transform)
[ 3, 2, 4 ]

compose(f, g) //=> g(f(x)) Is this the intended behaviour or should it be the other way ?

ubolonton commented 9 years ago

No, compose(f, g)(x) is f(g(x)), as expected.

The outer transducer (returned by f) processes the item before passing it to the inner transducer (returned by g). Roughly like this:

g(x): g-ing, then x
f(x): f-ing, then x
f(g(x)): f-ing, then g-ing, then x
deepak1556 commented 9 years ago

Ahh thanks!