Concatenation of array and range
user1234
user1234 at 12.de
Sun Jan 19 19:35:31 UTC 2025
On Sunday, 19 January 2025 at 18:57:51 UTC, Samuel Redding wrote:
> Hello there,
>
> is it possible to concat an array and a range? In Python one
> would have
> """
> list1 = [1, 2, 3]
> list1 += array.array('L', range(a, b))
> """
>
> The equivalent in D should be something like
> """
> ulong[] list1 = [1, 2, 3];
> list1 ~= iota(a, b);
> """
>
> I haven't found a way to do this. The only way to do it seems
> to extend "list1" and then iterate over the range and insert
> the elements.
iota is a lazy range. As shown in the other answer you can yield
the lazy thing using `.array`. But assuming it's ok to create a
distinctive iterator you can also chain the two things:
```d
auto list2 = std.range.chain(list1,iota(a,b));
```
with list2 being fully lazy.
More information about the Digitalmars-d
mailing list