Files
lo/docs/data/core-findduplicatesbyerr.md
T
Samuel Berthe fa095e4b4f fix(doc): fix go playground demo URL (#832)
* fix(doc): fix go playground demo URL

* fix(doc): add more go playground demo URL
2026-03-06 00:09:59 +01:00

40 lines
1.0 KiB
Markdown

---
name: FindDuplicatesByErr
slug: findduplicatesbyerr
sourceRef: find.go#L296
category: core
subCategory: find
playUrl: https://go.dev/play/p/HiVILQqdFP0
signatures:
- "func FindDuplicatesByErr[T any, U comparable, Slice ~[]T](collection Slice, iteratee func(item T) (U, error)) (Slice, error)"
variantHelpers:
- core#find#findduplicatesbyerr
similarHelpers:
- core#find#findduplicatesby
- core#find#findduplicates
- core#find#finduniques
- core#find#finduniquesby
position: 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.
```go
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:
```go
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")
```