Files
lo/docs/data/it-last.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

772 B

name, slug, sourceRef, category, subCategory, signatures, playUrl, variantHelpers, similarHelpers, position
name slug sourceRef category subCategory signatures playUrl variantHelpers similarHelpers position
Last last it/find.go#L389 it find
func Last[T any](collection iter.Seq[T]) (T, bool)
https://go.dev/play/p/eGZV-sSmn_Q
it#find#last
core#slice#last
it#find#first
it#find#lastor
130

Returns the last 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)
}
last, ok := it.Last(seq)
// last == 30, ok == true
seq := func(yield func(string) bool) {
    // empty sequence
}
last, ok := it.Last(seq)
// last == "", ok == false (zero value for string)