digitalmars.D.learn - std.range and opApply
- bearophile (23/23) May 18 2010 What's the attitude of std.range toward opApply?
What's the attitude of std.range toward opApply? In some situations I use opApply (and I think some syntax sugar can be added to define a yield, to make a third way to define lazy iterables in D) and I'd like to write code like this too: take(Range(100), 8) import std.range: isInputRange, take; struct Range { int stop; int opApply(int delegate(ref int) dg) { int result; for (int i = 0; i < stop; i++) { result = dg(i); if (result) break; } return result; } } void main() { assert(isInputRange!Range); auto r = take(Range(100), 8); } Is it planned to improve those std.range functions to work with opApply too, or do I have to rewrite them all and them some in my dlibs2, so they can support both the range protocol and opApply? Bye, bearophile
May 18 2010