Ruby-style "each" in D?

Meta jared771 at gmail.com
Wed Mar 19 10:27:03 PDT 2014


On Wednesday, 19 March 2014 at 16:46:41 UTC, Dicebot wrote:
> No, I don't mean iterate with predicate. I mean /dev/null thing.
>
> My point is that `range.each!predicate` is much better replaced 
> with `range.tap!predicate.consume`. It keeps general rule of 
> range stuff being lazy and only single exception to bail out of 
> it has very readable clear name.
>
> One can argue that "consume" is same as proposed "each" with 
> no-op predicate but I think it is very important for 
> readability to keep exceptional behavior (eager consumption) 
> separated from utility behavior (tapping with a predicate).

I also proposed this in the thread I linked, but it was also 
rejected. I remember Andrei saying that "consume" should really 
just be reduce called with no predicate, but I think that 
wouldn't work for some reason...


More information about the Digitalmars-d mailing list