Array.distinct
distincton
Group: Selections
Aliases: deduplicate
, unique
Documentation
Keeps only unique elements within the array, removing any duplicates.
The returned unique elements are kept in the same order as they appeared in the input. Out of multiple equivalent (equal up to the on
projection) elements, always the one appearing first in the input is kept.
Arguments
on
: A projection from the element type to the value of that element which determines the uniqueness criteria.
Examples
Removing repeating entries.
[1, 3, 1, 2, 2, 1].to_array . distinct == [1, 3, 2].to_array
Keeping only pairs whose first elements are unique.
[Pair 1 "a", Pair 2 "b", Pair 1 "c"].to_array . distinct (on = _.first) == [Pair 1 "a", Pair 2 "b"].to_array