How to discover what functions can be called on a type

What are the different ways using a Julia shell to discover what functions can be called on a type?

I am learning Julia as an experienced Python programmer. In python, I would open ipython, instantiate a variable of the type I wanted and hit . and see lots of functions dispatched on the type. I know Julia is multiple dispatch unlike Python, but I hope there is a simple way to see all the functions that I can call on a type.

My specific case is using counters from DataStructures. I read the docs https://juliacollections.github.io/DataStructures.jl/latest/accumulators.html.

In usage I can’t see that you can call nlargest on a counter result.

If I ?counter or ?cnt I don’t get any mention of nlargest, only functions that are somewhat spelled like the search term

I hope there is a way that aids discoverability?

using DataStructures cnt = counter(split("A B C 1 A 2 A B"))

Accumulator{SubString{String},Int64} with 5 entries: "B" => 2 "A" => 3 "1" => 1 "C" => 1 "2" => 1

2 Likes

Try

methodswith(typeof(cnt), supertypes=true)
3 Likes

Thank you. That gets me an array of methods.

methodswith(Accumulator) was also helpful.

Is there a simpler way to see the help for this list than manually typing each method into the help shell?

I tried
julia> map(? , methodswith(Accumulator))
ERROR: syntax: invalid identifier name "?"

and

map(Docs.getdoc , methodswith(Accumulator))
which returns an array of nothing 29-element Array{Nothing,1}:

You can do something like

foreach(methodswith(typeof(cnt), supertypes=true)) do m
    display(Docs.doc(Docs.Binding(m.module, m.name), m.sig))
end
2 Likes

Thank you. Works well.