lo
lo copied to clipboard
Filter() doesn’t preserve type
package main
import (
"fmt"
"github.com/samber/lo"
)
type intSlice []int
func main() {
s1 := intSlice{3, 4, 5}
s2 := lo.Filter(s1, func(_ int, _ int) bool { return true })
i1 := any(s2)
s3 := i1.(intSlice)
fmt.Printf("s3: %#v", s3)
}
^^ The above panics because s2 is of type []int
, not intSlice
.
Filter()
seems like it should return intSlice
here instead.
Thats because intslice is already a slice. You will get a slice of slices.
@jcbritobr See the linked PR for a fix with test.