samber / lo

💥 A Lodash-style Go library based on Go 1.18+ Generics (map, filter, contains, find...)
https://pkg.go.dev/github.com/samber/lo
MIT License
17.67k stars 814 forks source link

lop.PartitionBy does not guarantee the same order #510

Open nicewook opened 2 months ago

nicewook commented 2 months ago

I have tested the example of lop.PartitionBy on README.md It keep changed the order

dengyunsheng250 commented 2 months ago

well i have tested in bash file and it always return the same result

nicewook commented 1 day ago

sorry for confusion. I mean the parallel version. belows are my test and the result

func ExamplePartitionByParallel3() {
    partitions := lop.PartitionBy([]int{-2, -1, 0, 1, 2, 3, 4, 5}, func(x int) string {
        if x < 0 {
            return "negative"
        } else if x%2 == 0 {
            return "even"
        }
        return "odd"
    })
    fmt.Println(partitions)
    // Output:
    // [[-2 -1], [0 2 4], [1 3 5]]
}

result

=== RUN   ExamplePartitionByParallel3
--- FAIL: ExamplePartitionByParallel3 (0.00s)
got:
[[5 1 3] [2 4 0] [-2 -1]]
want:
[[-2 -1], [0 2 4], [1 3 5]]