Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Returned Dictionaries.Dictonary type does not adhere to Julia Dict interface #57

Open
kmacdough opened this issue Aug 7, 2022 · 3 comments

Comments

@kmacdough
Copy link

I was expecting to be able to iterate through these grouped dictionaries, but I'm noticing they do not seem to follow the AbstractDict interface. Is this an intentional design decision? If so, is there a benefit to this counterintuitive behavior?

julia> group(iseven, 1:5)
2-element Dictionaries.Dictionary{Bool, Vector{Int64}}
 false │ [1, 3, 5]
  true │ [2, 4]

julia> Dict(false => [1, 3, 5], true => [2, 4])
Dict{Bool, Vector{Int64}} with 2 entries:
  0 => [1, 3, 5]
  1 => [2, 4]

julia> collect(group(iseven, 1:5))
2-element Vector{Vector{Int64}}:
 [1, 3, 5]
 [2, 4]

julia> collect(Dict(false => [1, 3, 5], true => [2, 4]))
2-element Vector{Pair{Bool, Vector{Int64}}}:
 0 => [1, 3, 5]
 1 => [2, 4]
@andyferris
Copy link
Member

Yes. Take a look at e.g. https://discourse.julialang.org/t/splitapplycombine-jl-group-enhancements-reaches-version-1-0-0/32675

In your example we can do something like length.(group(iseven, 1:5)). You can convert the result to a Dict straightforwardly if that works better for you.

With Dict we can’t use things like map and broadcast. Dictionaries.jl is an attempt to bring the niceties of working with arrays in Julia to dictionaries and sets, too.

Does that make sense?

@kmacdough
Copy link
Author

@andyferris Ah yes, this definitely makes sense! Messing around with the package more I can definitely see the power in that decision.

I see now there's a note in the README, but it's pretty easy to overlook tacked at the end of the quick start, and I wouldn't have thought much of it had I noticed it. Might it be worth putting it somewhere more prominent & noting the consequences/utility of the decision? It does create a significant behavior divergence from the core libraries, and I expect I'm not the first naive user of the library thrown off by this.

If you're interested, I'd be happy to throw up a PR to that effect when I find some time.

@andyferris
Copy link
Member

Yes the documentation could definitely be improved. In fact, a lot of the usage documentation lives elsewhere like in the TypedTables docs. Contributions are welcome :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants