Dynamic chain for ranges?

Steven Schveighoffer schveiguy at gmail.com
Mon Jun 13 13:22:52 UTC 2022


On 6/13/22 4:51 AM, Ola Fosheim Grøstad wrote:
> Is there a dynamic chain primitive, so that you can add to the chain at 
> runtime?
> 
> Context: the following example on the front page is interesting.
> 
> ```d
> void main()
> {
>      int[] arr1 = [4, 9, 7];
>      int[] arr2 = [5, 2, 1, 10];
>      int[] arr3 = [6, 8, 3];
>      sort(chain(arr1, arr2, arr3));
>      writefln("%s\n%s\n%s\n", arr1, arr2, arr3);
> }
> ```
> 
> But it would be much more useful in practice if "chain" was a dynamic 
> array.
> 

`chain` allows ranges of different types.
`joiner` should be the equivalent for a dynamic range of ranges of the 
same type.

I would think sort(joiner([arr1, arr2, arr3])) should work, but it's not 
a random access range. Most likely because the big-O constants are no 
longer constant.

-Steve


More information about the Digitalmars-d-learn mailing list