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

Should "take" terminate right after reducing enough items? #9

Open ubolonton opened 9 years ago

ubolonton commented 9 years ago

This is probably not very important for collections. For js-csp channels, it would make quite a difference.

For example, in the current take implementation, if there is a take(5) channel, it can only close after 6 puts, not 5.

More generally speaking, is there a problem with having a class of transducers that reduces and terminates in the same step? Like this

return new Reduced(r(result, something_computed_from_input));
jlongster commented 9 years ago

Interesting. I don't think that violates any of the transducers semantics. I'll merge in your PR and test a few things to make sure it's ok.

jlongster commented 9 years ago

It's also worth mentioned that we do more work in take now, which might be a perf hit, so just need to benchmark and make sure it's not too bad.