digitalmars.D - request: indexed(inputRange, sortedInputRange)
- timotheecour (23/23) Mar 07 2013 right now std.range.indexed takes a randomAccessRange of elements
right now std.range.indexed takes a randomAccessRange of elements and a inputRange of indexes. Why not also support lazy inputs, with sorted integral indexes ? That's make it possible to, say, get every 10 lines of a file, lazily. right now: struct Indexed(Source, Indices) if (isRandomAccessRange!(Source) && isInputRange!(Indices) && is(typeof(Source.init[ElementType!(Indices).init]))); Indexed!(Source, Indices) indexed(Source, Indices)(Source source, Indices indices); here's what's proposed, in addition to above: struct Indexed(Source, Indices) if (isInputRange!(Source) && isSortedInputRange!(Indices) && isIntegral!(ElementType!(Indices))); Indexed!(Source, Indices) indexed(Source, Indices)(Source source, Indices indices); where a SortedInputRange represents a sorted input range (we could for eg construct one as assumeSorted()), and it there could be CT optimizations based on the type (eg: Iota would be sorted). Implementation: simply call popFront indexes[0] times and then popFront indexes[i+1]-indexes[i] times for each subsequent index.
Mar 07 2013