# \[Feature\] why not a \`functionswith\` method?

**URL:** <https://discourse.julialang.org/t/feature-why-not-a-functionswith-method/35409>\
**Category:** Internals & Design\
**Created:** [March 2, 2020, 2:26pm UTC](https://discourse.julialang.org/t/feature-why-not-a-functionswith-method/35409 "2020-03-02T14:26:56Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Iagoba\_Apellaniz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/iagoba_apellaniz/32/34406_2.png) [@Iagoba\_Apellaniz](https://discourse.julialang.org/u/Iagoba_Apellaniz)\
**Post date:** [March 2, 2020, 2:26pm UTC](https://discourse.julialang.org/t/feature-why-not-a-functionswith-method/35409/1 "2020-03-02T14:26:56Z")

</div>

The idea is to print a simpler and shorter list than `methodswith`. Since we have `methodswith` and `methods`, and the function name of a method is obtained by accessing it `name` field, for me it seems that `functionswith` is missing somehow. I think it would be useful.

---

<div class="post-metadata">

**Author:** ![visr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/visr/32/17204_2.png) [@visr](https://discourse.julialang.org/u/visr)\
**Post date:** [March 2, 2020, 2:33pm UTC](https://discourse.julialang.org/t/feature-why-not-a-functionswith-method/35409/2 "2020-03-02T14:33:09Z")

</div>

While not exactly what you are looking for, there is `apropos`, which searches the whole docstring for a specified string:

```julia
help?> apropos
search: apropos hasproperty

  apropos(string)

  Search through all documentation for a string, ignoring case.

julia> apropos("filter")
Base.:!
Base.FilteringRF
Base.filter
Base.Generator
Base.filter!
Base.Iterators.filter
Base.CoreLogging.AbstractLogger
Base.CoreLogging.min_enabled_level
Base.CoreLogging.LogLevel
Base.CoreLogging.handle_message
Base.Math._approx_cbrt
Base.Math._ldexp_exp
Base.StackTraces.from
LibGit2.diff_files
LibGit2.CheckoutOptions
Logging
Logging.Logging
Logging.ConsoleLogger
Test.@test_logs

```

Does that also cover your needs?

---

<div class="post-metadata">

**Author:** ![Iagoba\_Apellaniz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/iagoba_apellaniz/32/34406_2.png) [@Iagoba\_Apellaniz](https://discourse.julialang.org/u/Iagoba_Apellaniz)\
**Post date:** [March 2, 2020, 3:20pm UTC](https://discourse.julialang.org/t/feature-why-not-a-functionswith-method/35409/3 "2020-03-02T15:20:18Z")

</div>

I mean to use `functionswith` as

```julia
julia> functionswith(Int64) 
82-element Array{Symbol,1}:
 :/
 :rem
 :&
 :*
 :+
 :-
 :<
 :<<       
 :<=
 :(==)
 :>>
 :>>>
 ⋮
 :middle
 :clear!
 :serialize
 :nlargest
 :nsmallest
 :reset!
 :update!
 :tofirst
 :tolast
 :tonext
 :toprev
 :connect

```

Indeed I have something implemented

```julia
functionswith(X) = unique(map((x)->getfield(x,:name), methodswith(X)))

```

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [March 2, 2020, 3:39pm UTC](https://discourse.julialang.org/t/feature-why-not-a-functionswith-method/35409/4 "2020-03-02T15:39:38Z")

</div>

You should use the function rather than the name. The name has little significance.

---

<div class="post-metadata">

**Author:** ![Iagoba\_Apellaniz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/iagoba_apellaniz/32/34406_2.png) [@Iagoba\_Apellaniz](https://discourse.julialang.org/u/Iagoba_Apellaniz)\
**Post date:** [March 2, 2020, 3:48pm UTC](https://discourse.julialang.org/t/feature-why-not-a-functionswith-method/35409/5 "2020-03-02T15:48:31Z")

</div>

Thanks Yuyichao, but I don’t know how to do that… sorry

---

<div class="post-metadata">

**Author:** ![tkluck](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkluck/32/15769_2.png) [@tkluck](https://discourse.julialang.org/u/tkluck)\
**Post date:** [March 2, 2020, 3:53pm UTC](https://discourse.julialang.org/t/feature-why-not-a-functionswith-method/35409/6 "2020-03-02T15:53:29Z")

</div>

Something like this might do the trick:

```julia
julia> functionswith(T) = unique(fieldtype(method.sig, 1).instance for method in methodswith(T))
functionswith (generic function with 1 method)

julia> functionswith(Int)
67-element Array{Function,1}:
 middle (generic function with 6 methods)
 clear! (generic function with 7 methods)
 serialize (generic function with 53 methods)
 rem (generic function with 139 methods)
 & (generic function with 16 methods)
...

```

There’s a few corner cases where this will error but maybe it’s a useful starting point.

FWIW, the corner cases are a good illustration why it’s hard to create something like your request. Consider the following definition:

```julia
julia> (::Val{N})(x::NTuple{N}) where N = N

julia> Val(3)((4,5,6))
3

```

This gives us a method that’s not associated to a well-defined function, because there’s a `where` clause over both the function and the argument:

```julia
julia> @which Val(3)((4,5,6))
(::Val{N})(x::Tuple{Vararg{T,N}} where T) where N in Main at REPL[12]:1

julia> (@which Val(3)((4,5,6))).sig
Tuple{Val{N},Tuple{Vararg{T,N}} where T} where N

```

This illustrates why `methodswith` is in `Base` but not `functionswith`. Does that help?

---

<div class="post-metadata">

**Author:** ![Iagoba\_Apellaniz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/iagoba_apellaniz/32/34406_2.png) [@Iagoba\_Apellaniz](https://discourse.julialang.org/u/Iagoba_Apellaniz)\
**Post date:** [March 2, 2020, 4:11pm UTC](https://discourse.julialang.org/t/feature-why-not-a-functionswith-method/35409/7 "2020-03-02T16:11:12Z")

</div>

Sure! I think this could be used in somoe IDEs to suggest you functions based on a variable you type… for instance this happens in single dispatched languajes and helps a lot for the discoverability of the functionalities of different types. I just took a screenshot of a JavaScript console suggesting you some methods for `x = 1`.  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/2/2/22ad36d432bebf1d00e6f9a851f3a3bd44bd6f96.png)

I think `functionswith` is not a bizzarre idea, and might be in `InteractiveUtils`. If that’s not the case, it was nice to discusse this with all you guys, and I’m very thankful.

Thanks

PS, I’ll cite this in a Juno.jl feature request issue
