-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
filter(f, ::Dict)
inconsistency
#17886
Comments
filter(f, Dict)
inconsistencyfilter(f, ::Dict)
inconsistency
I understand there is a convenience difference here, but that has been alleviated with the new guard comprehension syntax. Now there's Dict(k => v for (k, v) in d if k < v) So the convenience argument is nullified somewhat. The argument in favour of one-arg is less surprise, and easier generic programming on iterables. |
I just ran into the same inconsistency, this time against _ _ _(_)_ | A fresh approach to technical computing
(_) | (_) (_) | Documentation: https://docs.julialang.org
_ _ _| |_ __ _ | Type "?help" for help.
| | | | | | |/ _` | |
| | |_| | | | (_| | | Version 0.7.0-DEV.1246 (2017-08-05 10:31 UTC)
_/ |\__'_|_|_|\__'_| | Commit 472353c089 (6 days old master)
|__/ | x86_64-linux-gnu
julia> d = Dict(1=>1)
Dict{Int64,Int64} with 1 entry:
1 => 1
julia> first(filter((kv) -> true, d))
ERROR: MethodError: no method matching (::##1#2)(::Int64, ::Int64)
Closest candidates are:
#1(::Any) at REPL[2]:1
Stacktrace:
[1] filter(::##1#2, ::Dict{Int64,Int64}) at ./associative.jl:361
julia> first(filter((k, v) -> true, d))
1 => 1
julia> first(Iterators.filter((kv) -> true, d))
1 => 1
julia> first(Iterators.filter((k, v) -> true, d))
ERROR: MethodError: no method matching (::##7#8)(::Pair{Int64,Int64})
Closest candidates are:
#7(::Any, ::Any) at REPL[5]:1
Stacktrace:
[1] start_filter at ./iterators.jl:286 [inlined]
[2] start(::Base.Iterators.Filter{##7#8,Dict{Int64,Int64}}) at ./iterators.jl:281
[3] first(::Base.Iterators.Filter{##7#8,Dict{Int64,Int64}}) at ./abstractarray.jl:148 |
This inconsistency is part of the API consistency fixes that we need for 1.0. I believe @JeffBezanson has already thought and worked towards addressing this, but this issue is one specific problem. |
fix #17886, `filter[!]` on dicts should pass 1 argument to the function
filter
is inconsistent with its cousinmap
:but
I think the
map
behaviour makes more sense and is more consistent with the rest of the language.To summarize:
The text was updated successfully, but these errors were encountered: