.array changes the order

thedeemon via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu May 12 03:02:46 PDT 2016


On Thursday, 12 May 2016 at 09:44:39 UTC, xtreak wrote:
> I came across the issue where using .array after .joiner caused 
> the changes to the output. The program is at 
> https://dpaste.dzfl.pl/0885ba2eddb4 . I tried to debug through 
> the output but I couldn't get the exact issue. It will be 
> helpful if someone confirms this as a bug.

It's not a bug per se, just probably documentation being not 
clear enough. Essentially it's the same issue as with 
File.byLine: a range that mutates its state, so it's ok to 
consume lazily but if you just store references (as array() does) 
you get references to the same mutated value as result.

Quick fix:

   r.chunks(2).map!permutations.joiner.map!array.array.writeln;

i.e. copy each permutation to separate array before it's gone.


More information about the Digitalmars-d-learn mailing list