www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Phobos lacks a particular family of range functions...

reply Basile B. <b2.temp gmx.com> writes:
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.
Oct 21 2016
parent Basile B. <b2.temp gmx.com> writes:
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.
Oct 22 2016