documentcloud / underscore-contrib

The brass buckles on Underscore's utility belt
MIT License
621 stars 117 forks source link

add unfoldr #20

Open michaelficarra opened 11 years ago

michaelficarra commented 11 years ago

A case for it was made in documentcloud/underscore#696, but it was deemed unworthy of core underscore. It seems perfect for underscore-contrib. We can use prelude-ls's implementation (without the auto-currying).

puffnfresh commented 11 years ago

:+1:

fogus commented 11 years ago

So one think that I think is odd is that it relies on returning null to signal that a producer is done. I'd rather see an "official" done sentinel integrated into Underscore first. It seems like a legitimate addition -- with debate.

raganwald commented 11 years ago

I'd rather see an "official" done sentinel

Something like:

_.DONE = new Object();

_.isDone = function (value) { return value === _.DONE; };

???

If so, I wonder whether the exact same scheme should be ported to the trampoline function and to the functional iterators? They currently return undefined, mostly because I abhor business logic ever passing undefined around deliberately and it feels a little like working with an array.

If we don't use a sentinel, I urge us to consider returning undefined instead of null.

fogus commented 11 years ago

I would definitely want to change the trampoline to use _.DONE and it makes sense to do so for the iterators too. Good call.

joshuacc commented 11 years ago

Is there an underscore issue for the _.DONE sentinel? If not, should I open one up over there?

fogus commented 11 years ago

I've never seen one, but DONE is still useful.