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

Make length.(keys) work #19577

Closed
cossio opened this issue Dec 13, 2016 · 2 comments
Closed

Make length.(keys) work #19577

cossio opened this issue Dec 13, 2016 · 2 comments

Comments

@cossio
Copy link
Contributor

cossio commented Dec 13, 2016

Try this:

d = Dict([1,2] => 1.1, [3,2] => 0.1)
length.(keys(d))

It doesn't work on 0.5 (I've been told it works on master, https://discourse.julialang.org/t/length-keys-d-does-not-work/913). Can we pull this into 0.5.1?

@nalimilan
Copy link
Member

Looks like I was mistaken. Here's what this returns on master:

julia> length.(keys(d))
2

So actually it just falls back to length(keys(d)). That's a more general problem with iterators, as length.(1:2 for i in 1:3) returns 3 rather than [2, 2, 2] too. I guess that's a matter of defining broadcast_indices for these objects.

Ironically, it's easier to fix on 0.5 than on master, since defining Base.size(x::Base.KeyIterator) = (length(x),) is enough for the former, but not for the latter.

@mbauman
Copy link
Sponsor Member

mbauman commented Sep 15, 2017

Mostly a duplicate of #20678/#10092.

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

3 participants