mirror of
https://github.com/samber/lo.git
synced 2026-04-22 23:47:11 +08:00
997 B
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 |
|
|
|
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"