passing predicates to lowerBound, or alternatively, how lazy is map?

Andrew Brown via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Jun 11 07:22:04 PDT 2014


So I was hoping for a learning experience, and I got it. With a 
little playing around, looking at phobos, and TDPL, I think I've 
figured out how lowerBound gets its predicate. It learns it from 
assumeSorted. So I can do this:

order.assumeSorted!((a, b) => number[a] < number[b])
      .lowerBound(order[4])

and I'll retrieve the indices of the 4 smallest numbers. Not 
useful for my current purposes, but is getting me closer to 
figuring out how higher level functions and ranges work.

Thanks

Andrew



More information about the Digitalmars-d-learn mailing list