Back to Lo

It First

docs/data/it-first.md

1.53.0458 B
Original Source

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

Examples:

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