joiner: How to iterate over immutable ranges?

Bastiaan Veelo via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Feb 15 06:25:27 PST 2016


On Monday, 15 February 2016 at 01:14:10 UTC, Ali Çehreli wrote:
> On 02/14/2016 11:32 AM, Bastiaan Veelo wrote:
>
> If it's acceptable for you, the following code calls .save on 
> the elements and it works:
>
> import std.algorithm.iteration;
> import std.stdio;
> import std.array;    // <-- ADDED
>
> void main()
> {
>     immutable(string[])[] icycles;
>     icycles ~= ["one", "two"];
>     icycles ~= ["three", "four"];
>     foreach (number; icycles.map!(r => r.save).joiner)
>         writeln(number);
> }
>
> Again, .save on an array is cheap. What will happen is that the 
> original immutable arrays will be untouched but their proxies 
> returned by .save will be consumed.

Great, thanks. I didn't even know about save... Its documentation 
is hidden quite well, because I still cannot find it. Seems it is 
about time I read the books.


More information about the Digitalmars-d-learn mailing list