Re: Getting equivalent elements in a range/array

2011-05-08 Thread Andrej Mitrovic
Thanks, group seems to work fine too.

Re: Getting equivalent elements in a range/array

2011-05-08 Thread bearophile
Andrej M.: > I want to turn this: > auto arr = [1, 1, 2, 3, 4, 4]; > > into this: > auto arr2 = [[1, 1], [2], [3], [4, 4]]; > > I want an array of arrays of the same elements. Lazy or not, I don't care. Currently if you use group like this: writeln(arr.group()); You get: [Tuple!(int,uint)(1, 2

Re: Getting equivalent elements in a range/array

2011-05-07 Thread Andrej Mitrovic
Fantastic work, thanks! I'll look into more detail tomorrow, but it looks good so far. Just added a function helper and made the struct typed: import std.array; import std.range; struct EquivalentElements(T) { T range; T front_; this(T range) { this.range = range; this.

Re: Getting equivalent elements in a range/array

2011-05-07 Thread Ali Çehreli
On 05/07/2011 09:07 PM, Andrej M. wrote: I want to turn this: auto arr = [1, 1, 2, 3, 4, 4]; into this: auto arr2 = [[1, 1], [2], [3], [4, 4]]; I want an array of arrays of the same elements. Lazy or not, I don't care. I thought I could get away with this inside some while loop: auto equals =

Getting equivalent elements in a range/array

2011-05-07 Thread Andrej M.
I want to turn this: auto arr = [1, 1, 2, 3, 4, 4]; into this: auto arr2 = [[1, 1], [2], [3], [4, 4]]; I want an array of arrays of the same elements. Lazy or not, I don't care. I thought I could get away with this inside some while loop: auto equals = array(filter!"a == b"(arr)); arr = arr[equa