Back to Lo

Core Foreachwhile

docs/data/core-foreachwhile.md

1.53.0321 B
Original Source

Iterates over elements of a collection and invokes the predicate for each element until false is returned.

go
numbers := []int64{1, 2, -9223372036854775808, 4}
lo.ForEachWhile(numbers, func(x int64, _ int) bool {
    if x < 0 {
        return false
    }
    fmt.Println(x)
    return true
})
// Output:
// 1
// 2