Files
lo/docs/data/it-dropslice.md
T
2025-10-06 17:16:33 +02:00

2.0 KiB

name, slug, sourceRef, category, subCategory, signatures, variantHelpers, similarHelpers, position
name slug sourceRef category subCategory signatures variantHelpers similarHelpers position
DropLast dropslice it/seq.go#L510 it slice
func DropLast[T any, I ~func(func(T) bool)](collection I, n int) I
func DropByIndex[T any, I ~func(func(T) bool)](collection I, indexes ...int) I
func Subset[T any, I ~func(func(T) bool)](collection I, offset, length int) I
func Slice[T any, I ~func(func(T) bool)](collection I, start, end int) I
it#slice#droplast
it#slice#dropbyindex
it#slice#subset
it#slice#slice
core#slice#drop
core#slice#droplast
core#slice#dropbyindex
core#slice#subset
core#slice#slice
150

DropLast drops n elements from the end of a sequence.

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

filtered := it.DropLast(collection, 2)
var result []int
for item := range filtered {
    result = append(result, item)
}
// result contains [1, 2, 3]

DropByIndex drops elements from a sequence by the index.

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

filtered := it.DropByIndex(collection, 1, 3)
var result []int
for item := range filtered {
    result = append(result, item)
}
// result contains [1, 3, 5]

Subset returns a subset of a sequence from offset up to length elements.

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

subset := it.Subset(collection, 2, 3)
var result []int
for item := range subset {
    result = append(result, item)
}
// result contains [3, 4, 5]

Slice returns a subset of a sequence from start up to, but not including end.

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

sliced := it.Slice(collection, 1, 4)
var result []int
for item := range sliced {
    result = append(result, item)
}
// result contains [2, 3, 4]