How would one remove duplicates from an unordered Immutable.List()? (without using toJS() or toArray())
e.g.
Immutable.List.of("green", "blue","green","black", "blue")
How would one remove duplicates from an unordered Immutable.List()? (without using toJS() or toArray())
e.g.
Immutable.List.of("green", "blue","green","black", "blue")
You can convert it to a Set. A Set is a List with unique values.
Immutable.List.of("green", "blue","green","black", "blue").toSet()
If you need it as list again just convert it back then:
Immutable.List.of("green", "blue","green","black", "blue").toSet().toList()
Update:
It exists a shorter possibility to get unique values:
Immutable.List.of("green", "blue","green","black", "blue").distinct
If you have a more complex type you can also use groupBy to provide your own selector to compare on. The following will remove duplicates on the property .name
:
var distinctColors = duplicateColors.groupBy(x => x.name).map(x => x.first()).toList();