import std.stdio : writeln; import std.algorithm : sort; import std.typecons : tuple; auto xs = [ tuple("a", 1.0), tuple("b", 3.0), tuple("a", 2.0), tuple("b", 4.0)]; auto grouped = xs.groupBy!((a) => a[0]); assertEqual( grouped.keys.length, 2 ); assertEqual( grouped.keys.sort(), ["a","b"].sort() );