Logo

Programming-Idioms

History of Idiom 119 > diff from v6 to v7

Edit summary for version 7 by :
New D implementation by user [cym13]

Version 6

2016-01-15, 12:57:36

Version 7

2016-01-24, 02:53:25

Idiom #119 Deduplicate list

Remove duplicates from list x.
Explain if original order is preserved.

Idiom #119 Deduplicate list

Remove duplicates from list x.
Explain if original order is preserved.

Imports
import std.algorithm;
import std.array;
Code
x = x.sort.uniq.array;
Comments bubble
uniq takes and output a range which could be infinite so it only looks for adjacent duplicates. That's why we sort x beforehand.
Doc URL
http://dlang.org/phobos/std_algorithm_iteration.html#.uniq