Back to Lo

It Droplast

docs/data/it-droplast.md

1.53.0617 B
Original Source

Drops the last n elements from a sequence. Returns a new sequence without the specified number of trailing elements.

go
seq := func(yield func(int) bool) {
    yield(1)
    yield(2)
    yield(3)
    yield(4)
    yield(5)
}
result := it.DropLast(seq, 2)
// iter.Seq[int] yielding 1, 2, 3

result = it.DropLast(seq, 0)
// iter.Seq[int] yielding 1, 2, 3, 4, 5 (unchanged)

result = it.DropLast(seq, 10)
// iter.Seq[int] yielding nothing (all elements dropped)

seq = func(yield func(string) bool) {
    yield("a")
    yield("b")
    yield("c")
}
result = it.DropLast(seq, 1)
// iter.Seq[string] yielding "a", "b"