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

The cat and mapcat transformers do not pass on the reduced status #23

Open odf opened 9 years ago

odf commented 9 years ago

Thanks for this fantastic library. I've noticed a little problem with cat (and consequently with mapcat) that is demonstrated in the following gist: https://gist.github.com/odf/ae937c46f7f95e9e4e57

The issue here is that the step method of the internal transformer used within Cat#step unwraps (derefs) a reduced value, but in fact should put an extra wrapper around it, due to the fact that one will be removed by the reduce call in Cat#step. This means that effectively in a composed transformer, an inner take or takeWhile will be ignored by an outer mapcat, and we loose part of the ability to deal sanely with things like 'infinite' lazy seqs or channels.

The fix is very small, but I'm happy to prepare a pull request if you like.

PS: I had to cheat and look up the proper handling of reduced values in cat in the Clojure implementation.