Skip to content

Filter() doesn’t preserve type #364

@FGasper

Description

@FGasper
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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions