You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The existing lo.ForEach function makes a copy of every element as it iterates, which is problematic for arrays since that prevents them from being modified.
Example:
type Dummy struct {
f1 string
}
a := []Dummy{{f1: "Hello"}}
fmt.Println(a)
lo.ForEach(a, func(d Dummy, _ int) {
d.f1 += ", world!"
})
fmt.Println(a)
Output:
[{Hello}]
[{Hello}]
To resolve this, I would like to add a method ForEachByRef which would pass a ref to each array element in the function callback. With the new function, the above code would look like:
The existing
lo.ForEach
function makes a copy of every element as it iterates, which is problematic for arrays since that prevents them from being modified.Example:
Output:
To resolve this, I would like to add a method
ForEachByRef
which would pass a ref to each array element in the function callback. With the new function, the above code would look like:If that sounds fine, can I raise a PR to add this function?
The text was updated successfully, but these errors were encountered: