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

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
func FindDuplicatesByErr[T any, U comparable, Slice ~[]T](collection Slice, iteratee func(item T) (U, error)) (Slice, error)
core#find#findduplicatesbyerr
core#find#findduplicatesby
core#find#findduplicates
core#find#finduniques
core#find#finduniquesby
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")