Ruby-style "each" in D?

Dicebot public at dicebot.lv
Wed Mar 19 09:46:40 PDT 2014


On Wednesday, 19 March 2014 at 16:40:24 UTC, Andrei Alexandrescu 
wrote:
> On 3/19/14, 9:09 AM, Dicebot wrote:
>> On Wednesday, 19 March 2014 at 16:04:16 UTC, Andrei 
>> Alexandrescu wrote:
>>> tee is already being discussed -- Andrei
>>
>> On this topic, do we have something like "consume" in Phobos 
>> to eagerly
>> iterate through the supplied range?
>
> A default "each" would do that.
>
> Andrei

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).


More information about the Digitalmars-d mailing list