Back to Lo

It Findduplicates

docs/data/it-findduplicates.md

1.53.0807 B
Original Source

Returns the first occurrence of each duplicated element in the collection (elements that appear more than once).

Examples:

go
seq := func(yield func(int) bool) {
    _ = yield(1)
    _ = yield(2)
    _ = yield(2)
    _ = yield(3)
    _ = yield(4)
    _ = yield(4)
    _ = yield(4)
}
dupSeq := it.FindDuplicates(seq)
var result []int
for v := range dupSeq {
    result = append(result, v)
}
// result contains 2, 4 (first occurrence of each duplicated element)
go
seq := func(yield func(string) bool) {
    _ = yield("apple")
    _ = yield("banana")
    _ = yield("apple")
    _ = yield("cherry")
    _ = yield("banana")
}
dupSeq := it.FindDuplicates(seq)
var result []string
for v := range dupSeq {
    result = append(result, v)
}
// result contains "apple", "banana" (duplicated elements)