MikeInnes / Lazy.jl

I was gonna maintain this package, but then I got high
Other
469 stars 54 forks source link

Return Array instead of Dict in function groupby #91

Open sgalal opened 6 years ago

sgalal commented 6 years ago

Hi! I am using the groupby function and I notice that the return type is Dict instead of Array.

https://github.com/MikeInnes/Lazy.jl/blob/432473450db3558c6ca63df718b1c2525c29595b/src/collections.jl#L44-L52

julia> groupby(x -> x[1], [(1,2,3), (2,2,3), (1,2,4), (2,3,4)])
Dict{Any,Any} with 2 entries:
  2 => Any[(2, 2, 3), (2, 3, 4)]
  1 => Any[(1, 2, 3), (1, 2, 4)]

Would it be better if the function returns an Array so the original order could be preserved? Like this:

julia> groupby(x -> x[1], [(1,2,3), (2,2,3), (1,2,4), (2,3,4)])
2-element Array{Any,1}:
 Any[(1, 2, 3), (1, 2, 4)]
 Any[(2, 2, 3), (2, 3, 4)]

Besides, in Haskell, the type signature of groupBy looks like:

groupBy :: (a -> a -> Bool) -> [a] -> [[a]]

which returns an Array.