Files
lo/docs/data/it-first.md
T
2025-10-08 19:35:53 +02:00

784 B

name, slug, sourceRef, category, subCategory, signatures, playUrl, variantHelpers, similarHelpers, position
name slug sourceRef category subCategory signatures playUrl variantHelpers similarHelpers position
First first it/find.go#L362 it find
func First[T any](collection iter.Seq[T]) (T, bool)
https://go.dev/play/p/5MgZD9-zl
it#find#first
core#slice#first
it#find#last
it#find#firstor
120

Returns the first element of a collection and a boolean indicating availability. Returns zero value and false if the collection is empty.

Examples:

seq := func(yield func(int) bool) {
    _ = yield(10)
    _ = yield(20)
    _ = yield(30)
}
first, ok := it.First(seq)
// first == 10, ok == true
seq := func(yield func(string) bool) {
    // empty sequence
}
first, ok := it.First(seq)
// first == "", ok == false (zero value for string)