Gozala / reducers

Library for higher-order manipulation of collections
MIT License
181 stars 8 forks source link

Make print chainable #42

Closed Raynos closed 10 years ago

Raynos commented 11 years ago
var enchain = require("enchain")
var chain = enchain(require("reducers"))

chain([1,2,3])
  .print()
  .map(function (x) { return x * 2 })
  .print()
  .etc()
Gozala commented 11 years ago

I don't like that since print in the chain may cause behavior change depending on the input since actual input will be consumed twice. I don't mind making things chainable, but it shoud be clean (and should be diff function). I pointed out something introspect few times I. I don't think that should be API but that gives you an idea. I want introspect to take:

introspect(input, {
   onValue: ..,
   onEnd: ...,
   onError: ...
}) => input
Raynos commented 11 years ago

@Gozala your right I think I want introspect.

However making print return a source isn't going to hurt anyone. I'm well aware it will reduce it twice which is fine in the cases that it's fine. Make your source side-effect free.

Gozala commented 11 years ago

@raynos no it's far from obvious that if my input is fs.read under the hood that it will read file twice. It can get confusing very quickly. I prefer not have APIs in the core that would trip up users. There is already big enough change from common patterns to scare a lot of users. It's important to keep balance.

But again that's not an issues for your use case just put your own function into chain instead of reducers print and problem solved.

P.S.: I'm even considering to move debug out of reducers into separate package.

Raynos commented 11 years ago

if you move debug out then also add introspect. It's introspect I want, not debug.

Raynos commented 11 years ago

@Gozala note my only use-case for print is for debugging my unit tests. It's very convenient for my chaining flow for it to just return the source.

Raynos commented 10 years ago

Closing this due to staleness