how to get top N distinct elements from range?

bearophile bearophileHUGS at lycos.com
Sat Mar 9 12:13:28 PST 2013


Andrei Alexandrescu:

> Yah,

There are 3 problems:
- In a successive post I have also added a template constraint, 
so Range is an InputRange.
- firstDistinct() packs two behaviours that are better kept 
separated, it's like a takeDistinct. It's better to remove the 
final take, and return all distinct items. If a user wants the 
first ones, he/she/shi will add a take after it. This is why 
later in this thread we have used distinct(). In very few cases 
I'd like some extra functions in Phobos like flatMap and amap, 
because they are very common operations. But in most cases it's 
better to keep only the simplest algorithms (like distinct and 
take), so you can combine them in many different ways.
- Successive posts have shown that the code doesn't work. After 
several tests I have opened this: 
http://d.puremagic.com/issues/show_bug.cgi?id=9674  Please take a 
look at it.
- I have recently written a little D program, about something 
else, that I think you will appreciate even more than that 
firstDistinct/distinct :-)

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list