Phobos lacks a particular family of range functions...

Basile B. via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Oct 22 04:06:44 PDT 2016


On Friday, 21 October 2016 at 19:41:00 UTC, Basile B. wrote:
> They would have for constraint
>
>   `if (isInputRange!Range && isInputRange!(ElementType!Range))`
>
> In case you wouldn't see directly what would they be used for, 
> it's for tree-like structures. Each element in a Range is also 
> an input range.
>
> I see 3 obvious functions/templates
>
> - the most important, make an input range from a tree-like 
> range, e.g `auto treeRange(Range, DepthMode mode)(Range range) `
>
> - a second version for bidir ranges, e.g `reverseTreeRange`
>
> - a functional iteration algorithm: auto `deepIterate(alias 
> Fun, DepthMode mode, Range, A...)(Range range, auto ref A a)`, 
> which applies Fun to each element with the ability for Fun to 
> act as a predicates to stop the iteration. Actually I have this 
> one in my user library (this is also the reason why I post this 
> today).
>
> Unless I'm blind I cannot see anything that handles trees with 
> a range interface in phobos.

If you want to get the spirit see: 
https://github.com/BBasile/iz/blob/master/import/iz/sugar.d#L1214

Now a few hours later I wonder if it could be a ndSlice job ? I 
haven't used it so far, so I ask.


More information about the Digitalmars-d-learn mailing list