Back to Lo

It Droplastwhile

docs/data/it-droplastwhile.md

1.53.0402 B
Original Source

DropLastWhile drops elements from the end of a sequence while the predicate returns true.

go
collection := func(yield func(int) bool) {
    yield(1)
    yield(2)
    yield(3)
    yield(4)
    yield(5)
}

filtered := it.DropLastWhile(collection, func(x int) bool {
    return x > 3
})
var result []int
for item := range filtered {
    result = append(result, item)
}
// result contains [1, 2, 3]