how to get top N distinct elements from range?

Andrea Fontana nospam at example.com
Fri Mar 8 07:53:55 PST 2013


On Friday, 8 March 2013 at 14:43:29 UTC, jerro wrote:
> On Friday, 8 March 2013 at 13:33:24 UTC, Andrea Fontana wrote:
>> I wonder if exists a way to get top n distinct elements from a 
>> range (infinite too!)
>
> It's impossible to do that for infinite ranges

Why?

sequence!"n*2".myTopDistinct!"a==b"(3);

will give [2,4,6]

We just need to keep a list of "just-seen" elements
But I don't know how to make it lazy


More information about the Digitalmars-d-learn mailing list