Logo

Programming-Idioms

History of Idiom 119 > diff from v7 to v8

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

Version 7

2016-01-24, 02:53:25

Version 8

2016-01-24, 03:05:21

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.

Code
bool[typeof(x[0])] aa;

foreach (elem ; x)
    aa[elem] = true;

x = aa.keys;
Comments bubble
Using an associative array. It uses "typeof(x[0])" to be generic, in a real code we would know the type of x and wouldn't need such trick.