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

683 B

name, slug, sourceRef, category, subCategory, signatures, variantHelpers, similarHelpers, position
name slug sourceRef category subCategory signatures variantHelpers similarHelpers position
Replace replace it/seq.go#L699 it slice
func Replace[T comparable, I ~func(func(T) bool)](collection I, old, nEw T, n int) I
it#slice#replace
core#slice#replace
190

Replace returns a sequence with the first n non-overlapping instances of old replaced by new.

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

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