Does not work.Uniq for uuid
mdwitr0 opened this issue · comments
Evgenii Fedoryachenko commented
We use the gofrs/uuid library to work with uuids. When trying to delete duplicates, we get an error
Sample
package main
import (
"fmt"
"github.com/gofrs/uuid"
"github.com/thoas/go-funk"
)
func main() {
ids := []uuid.UUID{
uuid.Must(uuid.NewV4()),
uuid.Must(uuid.NewV4()),
uuid.Must(uuid.NewV4()),
uuid.FromStringOrNil("ad51e1b7-c08f-4704-9e7f-71b254a491e3"),
uuid.FromStringOrNil("ad51e1b7-c08f-4704-9e7f-71b254a491e3"),
uuid.FromStringOrNil("ad51e1b7-c08f-4704-9e7f-71b254a491e3"),
}
unique := funk.Uniq(ids).([]uuid.UUID)
fmt.Println(unique)
}
Expected result: a unique list of UUIDs
But I get an error
Got a connection, launched process /Users/eugene/Library/Caches/JetBrains/GoLand2023.3/tmp/GoLand/___1go_build_crypto360_tmp (pid = 8487).
panic: reflect.Set: value of type uuid.UUID is not assignable to type uint8
goroutine 1 [running]:
reflect.Value.assignTo({0x10270ca80, 0x140001000c0, 0x191}, {0x1026dfbea, 0xb}, 0x1026f9e80, 0x0)
/opt/homebrew/Cellar/go/1.21.1/libexec/src/reflect/value.go:3307 +0x340
reflect.Value.Set({0x1026f9e80, 0x1400011e090, 0x188}, {0x10270ca80, 0x140001000c0, 0x191})
/opt/homebrew/Cellar/go/1.21.1/libexec/src/reflect/value.go:2260 +0xa8
reflect.Append({0x1026f8cc0, 0x1400011a138, 0x97}, {0x14000054ce8, 0x1, 0x1})
/opt/homebrew/Cellar/go/1.21.1/libexec/src/reflect/value.go:2881 +0x124
github.com/thoas/go-funk.Uniq({0x1026f8700, 0x1400011a0f0})
/Users/eugene/Go/pkg/mod/github.com/thoas/go-funk@v0.9.3/transform.go:406 +0x270
main.main()
/Users/eugene/developments/hfx/crypto360/tmp/main.go:19 +0x1d4
Exiting.
Flo commented
It's because, uuid.UUID
is not a supported type by funk.Uniq
you need to convert your slice to a []string
and it will work properly.