On Saturday, 6 October 2018 at 13:17:22 UTC, bauss wrote:
Let's say you have a range with struct, but some of the struct are duplicates of each other.

Is there a standard function in Phobos to remove duplicates?

My first thought was "uniq", but it can't really do it like that, but it doesn't work.

See: https://run.dlang.io/is/IcFEtw

Is there another function in Phobos that perhaps would work?

I can of course write my own function, but if there is a standard function that can do it, then I'd rather use that.

range
    .array.sort // make equal elements be adjacent
    .chunks!"a==b" // get a range over those equal elements
    .map(e => e.front); // get the first one

should work, possibly not the most efficient way to do it though.

I don't know off the top of mu head if there are any to preserve the order or the original range.

Reply via email to