Logo

Programming-Idioms

History of Idiom 119 > diff from v63 to v64

Edit summary for version 64 by alvarobrey:
New Kotlin implementation by user [alvarobrey]

Version 63

2019-09-27, 13:26:29

Version 64

2019-09-27, 13:33:51

Idiom #119 Deduplicate list

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

Illustration

Idiom #119 Deduplicate list

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

Illustration
Extra Keywords
deduplicate dupe dupes redundant redundancy undupe
Extra Keywords
deduplicate dupe dupes redundant redundancy undupe
Code
val duplicates = listOf("b", "a", "b", "c")
val noDuplicates = duplicates.distinct()
Comments bubble
Ordering is preserved
Doc URL
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/distinct.html
Demo URL
https://pl.kotl.in/DAYwRdvAN