Back to Lo

Core Find

docs/data/core-find.md

1.53.0333 B
Original Source

Searches for an element in a slice based on a predicate and returns the element with a boolean indicating success.

go
value, ok := lo.Find([]string{"a", "b", "c", "d"}, func(i string) bool {
    return i == "b"
})
// "b", true

value, ok = lo.Find([]string{"foobar"}, func(i string) bool {
    return i == "b"
})
// "", false