Re: Using std.algorithm how to uniq and sort a multidimensional array?

2014-01-29 Thread bearophile

Meta:


auto tags = tags.flatMap!uniq.array ?


That's another solution. In Phobos a flatMap can be useful (just 
as a zip overload that accepts a function to apply on the pairs, 
named zipWith in haskell: 
http://zvon.org/other/haskell/Outputprelude/zipWith_f.html ).


Bye,
bearophile


Re: Using std.algorithm how to uniq and sort a multidimensional array?

2014-01-28 Thread Gary Willoughby
On Tuesday, 28 January 2014 at 14:46:48 UTC, Gary Willoughby 
wrote:
Using std.algorithm how to uniq and sort a multidimensional 
array?


e.g. the uniq function takes a function as a predicate but i'm 
confused how to handle the multiple dimensions.


string[][] tags;

tags = tags.uniq!(a[0][1] == b[1][1]).array;

The above is my attempt and it failed.


Gah, it was simpler than i thought, of course.

tags = tags.sort!(a[1]  b[1]).uniq!(a[1] == b[1]).array;


Re: Using std.algorithm how to uniq and sort a multidimensional array?

2014-01-28 Thread Meta

On Tuesday, 28 January 2014 at 15:07:26 UTC, bearophile wrote:

Gary Willoughby:


   string[][] tags;

   tags = tags.uniq!(a[0][1] == b[1][1]).array;


I think the right abstraction for your use case is:

auto tags = tags.flatten.uniq.array;


auto tags = tags.flatMap!uniq.array ?