mirror of
https://github.com/samber/lo.git
synced 2026-04-22 15:37:14 +08:00
fa095e4b4f
* fix(doc): fix go playground demo URL * fix(doc): add more go playground demo URL
1.0 KiB
1.0 KiB
name, slug, sourceRef, category, subCategory, playUrl, signatures, variantHelpers, similarHelpers, position
| name | slug | sourceRef | category | subCategory | playUrl | signatures | variantHelpers | similarHelpers | position | ||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| FindDuplicatesByErr | findduplicatesbyerr | find.go#L296 | core | find | https://go.dev/play/p/HiVILQqdFP0 |
|
|
|
135 |
Returns a slice with the first occurrence of each duplicated element by key, preserving order. The iteratee can return an error to stop iteration immediately.
result, err := lo.FindDuplicatesByErr([]int{3, 4, 5, 6, 7}, func(i int) (int, error) {
return i % 3, nil
})
// []int{3, 4}, <nil>
Example with error:
result, err := lo.FindDuplicatesByErr([]int{3, 4, 5, 6, 7}, func(i int) (int, error) {
if i == 5 {
return 0, fmt.Errorf("number 5 is not allowed")
}
return i % 3, nil
})
// []int(nil), error("number 5 is not allowed")