can we have something like in std.algorithm ? it returns uniq elements in original order of appearance Some cleanup may be needed, please send comments! auto uniqStable(T)(T a) if(isRandomAccessRange!T){ return zip(a,iota(a.length)).array.sort!q{a[0] < b[0]}.array.uniq!q{a[0]==b[0]}.array.sort!q{a[1]<b[1]}.map!q{a[0]}.array; }