# Can methodswith() return everything?

**URL:** https://discourse.julialang.org/t/can-methodswith-return-everything/8026
**Category:** General Usage
**Tags:** proposal
**Created:** [December 27, 2017, 5:42pm UTC](https://discourse.julialang.org/t/can-methodswith-return-everything/8026 "2017-12-27T17:42:01Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![tk3369](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tk3369/32/2824_2.png) [@tk3369](https://discourse.julialang.org/u/tk3369)
#### Post date: [December 27, 2017, 5:42pm UTC](https://discourse.julialang.org/t/can-methodswith-return-everything/8026/1 "2017-12-27T17:42:01Z")

</div>

I **_love_** the `methodswith()` function as it lets me quickly find out the functions that take a particular type directly in the REPL without having to look up the type’s documentation on the web.

However, I found it to be too restrictive and it’s missing something. For example,

```julia
julia> methodswith(Dict)
29-element Array{Method,1}:
 convert(::Type{Dict{K,V}}, d::Dict{K,V}) where {K, V} in Base at dict.jl:208                                                                          
 copy(d::Dict) in Base at dict.jl:134                                                                                                                  
 delete!(h::Dict, key) in Base at dict.jl:558                                                                                                          
 done(t::Dict, i) in Base at dict.jl:578                                                                                                               
 empty!(h::Dict{K,V}) where {K, V} in Base at dict.jl:304                                                                                              
 get(h::Dict{K,V}, key, default) where {K, V} in Base at dict.jl:478                                                                                   
 get(default::Union{Function, Type}, h::Dict{K,V}, key) where {K, V} in Base at dict.jl:483                                                            
 get!(h::Dict{K,V}, key0, default) where {K, V} in Base at dict.jl:434                                                                                 
 get!(default::Union{Function, Type}, h::Dict{K,V}, key::K) where {K, V} in Base at dict.jl:444                                                        
 get!(default::Union{Function, Type}, h::Dict{K,V}, key0) where {K, V} in Base at dict.jl:436                                                          
 getindex(h::Dict{K,V}, key) where {K, V} in Base at dict.jl:473                                                                                       
 getkey(h::Dict{K,V}, key, default) where {K, V} in Base at dict.jl:527                                                                                
 haskey(h::Dict, key) in Base at dict.jl:505                                                                                                           
 isempty(t::Dict) in Base at dict.jl:581                                                                                                               
 launch(manager::Base.Distributed.SSHManager, params::Dict, launched::Array, launch_ntfy::Condition) in Base.Distributed at distributed/managers.jl:121
 launch(manager::Base.Distributed.LocalManager, params::Dict, launched::Array, c::Condition) in Base.Distributed at distributed/managers.jl:317        
 length(t::Dict) in Base at dict.jl:582                                                                                                                
 next(t::Dict{K,V}, i) where {K, V} in Base at dict.jl:579                                                                                             
 pop!(h::Dict, key) in Base at dict.jl:538                                                                                                             
 pop!(h::Dict, key, default) in Base at dict.jl:543                                                                                                    
 rand(r::AbstractRNG, t::Dict) in Base.Random at random.jl:374                                                                                         
 rand(t::Dict) in Base.Random at random.jl:381                                                                                                         
 serialize(s::AbstractSerializer, d::Dict) in Base.Serializer at serialize.jl:337                                                                      
 setindex!(h::Dict{K,V}, v0, key::K) where {K, V} in Base at dict.jl:420                                                                               
 setindex!(h::Dict{K,V}, v0, key0) where {K, V} in Base at dict.jl:412                                                                                 
 similar(d::Dict{K,V}) where {K, V} in Base at dict.jl:192                                                                                             
 similar(d::Dict, ::Type{Pair{K,V}}) where {K, V} in Base at dict.jl:193                                                                               
 sizehint!(d::Dict, newsz) in Base at dict.jl:274                                                                                                      
 start(t::Dict) in Base at dict.jl:574                                                                                                                 

```

In this case, `keys()` function isn’t returned. As it turns out, keys take the `Associative` type as its argument rather than Dict. It’s object-oriented, stupid! 😁

```julia
help?> keys
search: keys keytype KeyError haskey getkey WeakKeyDict takebuf_array

  keys(a::Associative)

  Return an iterator over all keys in a collection. collect(keys(a)) returns an array of keys. Since the keys are stored
  internally in a hash table, the order in which they are returned may vary. But keys(a) and values(a) both iterate a and return
  the elements in the same order.

  julia> a = Dict('a'=>2, 'b'=>3)
  Dict{Char,Int64} with 2 entries:
    'b' => 3
    'a' => 2
  
  julia> collect(keys(a))
  2-element Array{Char,1}:
   'b'
   'a'

```

I think it would be best if `methodswith` can return all functions that satisfy the contract. It’s a great utility!

---

<div class="post-metadata">

### Author: ![vchuravy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vchuravy/32/8_2.png) [@vchuravy](https://discourse.julialang.org/u/vchuravy)
#### Post date: [December 27, 2017, 6:02pm UTC](https://discourse.julialang.org/t/can-methodswith-return-everything/8026/2 "2017-12-27T18:02:39Z")

</div>

I think you are looking for `methodswith(Dict, true)` which will show all methods that are defined including for the supertypes of `T` (except `Any`).

(Also see the documentation for `methodswith`)

---

<div class="post-metadata">

### Author: ![tk3369](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tk3369/32/2824_2.png) [@tk3369](https://discourse.julialang.org/u/tk3369)
#### Post date: [December 27, 2017, 6:11pm UTC](https://discourse.julialang.org/t/can-methodswith-return-everything/8026/3 "2017-12-27T18:11:13Z")

</div>

Haha… Always learning something new 🙂  
Thanks, @vchuravy
