passing predicates to lowerBound, or alternatively, how lazy is map?
John Colvin via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Jun 11 05:40:15 PDT 2014
On Wednesday, 11 June 2014 at 11:50:36 UTC, Andrew Brown wrote:
>>
>> map is fully lazy.
>>
>> However, if you've already got the sorted indices in `order`,
>> I would do this:
>>
>> auto numLessThanN = numbers.indexed(order).countUntil!((x) => x
>> >= N)();
>
> That indexed command is perfect though, does the trick, thank
> you very much.
For future reference: map applies its predicate in `front`,
meaning that
a) It is completely lazy, you only pay for elements you actually
access.
b) Unless the optimiser is smart and caches the result for you,
you pay every time you call `front`, even if you haven't called
`popFront` in between.
More information about the Digitalmars-d-learn
mailing list