mirror of
https://github.com/samber/lo.git
synced 2026-04-22 23:47:11 +08:00
fa095e4b4f
* fix(doc): fix go playground demo URL * fix(doc): add more go playground demo URL
1.2 KiB
1.2 KiB
name, slug, sourceRef, category, subCategory, signatures, playUrl, variantHelpers, similarHelpers, position
| name | slug | sourceRef | category | subCategory | signatures | playUrl | variantHelpers | similarHelpers | position | |||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| FindDuplicates | findduplicates | it/find.go#L196 | it | find |
|
https://go.dev/play/p/dw-VLQXKijT |
|
|
90 |
Returns the first occurrence of each duplicated element in the collection (elements that appear more than once).
Examples:
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)
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)