-
-
Notifications
You must be signed in to change notification settings - Fork 937
Closed
Description
it.Replace captures n, so n-- persists across iterations ⇒ second time you iterate the sequence, replacements don't happen :(
package main
import (
"fmt"
"slices"
"github.com/samber/lo/it"
)
func main() {
seq := it.Replace(slices.Values([]int{1, 2, 1, 2, 1}), 1, 9, 2)
fmt.Println(slices.Collect(seq)) // expected: [9 2 9 2 1] actual: [9 2 9 2 1]
fmt.Println(slices.Collect(seq)) // expected: [9 2 9 2 1] actual: [1 2 1 2 1]
}Other it functions like Uniq create fresh state per iteration, so this looks unintentional. Real impact is small because most users collect the sequence once, is this considered a bug?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels