# Is there any way one could define a method to accept both Functions and Functors?

**URL:** <https://discourse.julialang.org/t/is-there-any-way-one-could-define-a-method-to-accept-both-functions-and-functors/136159>\
**Category:** General Usage\
**Created:** [March 12, 2026, 12:05am UTC](https://discourse.julialang.org/t/is-there-any-way-one-could-define-a-method-to-accept-both-functions-and-functors/136159 "2026-03-12T00:05:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [March 12, 2026, 12:05am UTC](https://discourse.julialang.org/t/is-there-any-way-one-could-define-a-method-to-accept-both-functions-and-functors/136159/1 "2026-03-12T00:05:48Z")

</div>

That is, without a Union. I still would like the function to be typed. So I don’t see

```julia-auto
g(f, a) = let
     f(a)
end

```

as a solution (`f` should be typed).

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [March 12, 2026, 12:18am UTC](https://discourse.julialang.org/t/is-there-any-way-one-could-define-a-method-to-accept-both-functions-and-functors/136159/2 "2026-03-12T00:18:39Z")

</div>

Well, you can require that your functor types declare themselves as subtypes of `Function` (which is an abstract type that can be used as the parent of any type!).

Otherwise I don’t see how to avoid duck-typing. Any type can be made callable in Julia, so there is no way to identify callable objects by type in general.

---

<div class="post-metadata">

**Author:** ![Stephen\_Vavasis](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stephen_vavasis/32/3389_2.png) [@Stephen\_Vavasis](https://discourse.julialang.org/u/Stephen_Vavasis)\
**Post date:** [March 12, 2026, 12:52am UTC](https://discourse.julialang.org/t/is-there-any-way-one-could-define-a-method-to-accept-both-functions-and-functors/136159/3 "2026-03-12T00:52:16Z")

</div>

See also: [Is `Base.Callable` OK to use? Should it be documented? · Issue #43491 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/issues/43491)

---

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [March 12, 2026, 1:09am UTC](https://discourse.julialang.org/t/is-there-any-way-one-could-define-a-method-to-accept-both-functions-and-functors/136159/4 "2026-03-12T01:09:15Z")

</div>

Good jumping off point, Stephen. Interesting discussion, that. Thank you.
