how to get top N distinct elements from range?

Andrea Fontana nospam at example.com
Fri Mar 8 16:35:00 PST 2013


On Friday, 8 March 2013 at 23:44:40 UTC, bearophile wrote:
> Simpler:
>
>
> import std.stdio, std.range, std.algorithm;
>
> void main() {
>     iota(5).map!((x) {
>         write("*");
>         return x;
>     }).filter!(_ => true).array;
> }

Chech this:

5.iota.map!((_) {
		auto x = uniform(0, 1000);
			writeln(" MAP-1 = ", x);
			return x;
	}).filter!(_ => true).map!((x){ writeln(" MAP-2 = ", x); return
x; })().array.writeln;

Here some function calls front() internally (filter? map?) to
check some conditions and triggers random creation again.


More information about the Digitalmars-d-learn mailing list