Files
lo/docs/data/it-droplast.md
T
2026-02-08 02:26:36 +01:00

997 B

name, slug, sourceRef, category, subCategory, signatures, variantHelpers, similarHelpers, position
name slug sourceRef category subCategory signatures variantHelpers similarHelpers position
DropLast droplast it/seq.go#L512 it sequence
func DropLast[T any, I ~func(func(T) bool)](collection I, n int) I
it#sequence#droplast
it#sequence#drop
it#sequence#dropwhile
it#sequence#droplastwhile
it#sequence#trim
it#sequence#trimsuffix
78

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

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"