protocol for using InputRanges

monarch_dodra monarchdodra at gmail.com
Thu Mar 27 12:17:17 PDT 2014


On Thursday, 27 March 2014 at 19:03:26 UTC, Andrei Alexandrescu 
wrote:
> On 3/27/14, 9:12 AM, monarch_dodra wrote:
>>> filter comes to mind. -- Andrei
>>
>> You *just* turned down a pull that did exactly that, for 
>> exactly the
>> same reasons.
>
> I was on the verge, and we need to discuss this more. A 
> constructor that does arbitrary work for a lazy range doesn't 
> sit well. -- Andrei

I still think there's ambiguity in the word "lazy". I think this 
is the distinction most make:

Not lazy:
//----
auto r = getSomeRange();
auto arr = someRange.array();
foreach( ref e ; arr)
     doSomething;
remove!fun(arr);
return arr;
//----

Lazy:
//----
return getSomeRange()
     .map!doSomething()
     .filter!fun()
     .array();
//----

What you are talking about (IMO) is better described as "eager" 
vs "not eager".

"A constructor does some work for a lazy range that does eager 
processing of its elements": I think this is a better 
description, and I think is acceptable.


More information about the Digitalmars-d mailing list