# \#functors

**URL:** https://discourse.julialang.org/tag/functors/1080.md

[Latest](https://discourse.julialang.org/latest.md) · [Categories](https://discourse.julialang.org/categories.md) · [Tags](https://discourse.julialang.org/tags.md)

---

## [\[ANN\] EnforcedTypeSignatureCallables.jl](https://discourse.julialang.org/t/ann-enforcedtypesignaturecallables-jl/117280)

<div class="topic-metadata">

**Author:** [@nsajko](https://discourse.julialang.org/u/nsajko)\
**Replies:** 10\
**Last updated:** [September 5, 2025, 12:59pm UTC](https://discourse.julialang.org/t/ann-enforcedtypesignaturecallables-jl/117280 "2025-09-05T12:59:06Z")

</div>

The EnforcedTypeSignatureCallables package is being registered: New package: EnforcedTypeSignatureCallables v1.0.0 by JuliaRegistrator · Pull Request #111416 · JuliaRegistries/General · GitHub Once it’s registered, this…

---

## [Should function-like objects be subtypes of Function?](https://discourse.julialang.org/t/should-function-like-objects-be-subtypes-of-function/107081)

<div class="topic-metadata">

**Author:** [@goerz](https://discourse.julialang.org/u/goerz)\
**Replies:** 1\
**Last updated:** [December 3, 2023, 7:58pm UTC](https://discourse.julialang.org/t/should-function-like-objects-be-subtypes-of-function/107081 "2023-12-03T19:58:23Z")

</div>

For a function-like object, aka callable/functor, is there any problem with making it a subtype of Function? As in, struct Polynomial{R} \<: Function # XXX coeffs::Vector{R} end (p::Polynomial)(t) = evaluate\_polyn…

---

## [Inconsistency between map and fmap](https://discourse.julialang.org/t/inconsistency-between-map-and-fmap/106217)

<div class="topic-metadata">

**Author:** [@FerreolS](https://discourse.julialang.org/u/FerreolS)\
**Replies:** 2\
**Last updated:** [November 14, 2023, 3:48pm UTC](https://discourse.julialang.org/t/inconsistency-between-map-and-fmap/106217 "2023-11-14T15:48:38Z")

</div>

Hi, I saw fmap as an extension of map to functors and I want to use it convert type of element of arrays that are leaves of some struct: Taking the doc example: julia\> using Functors julia\> struct Foo x …

---

## [How to get methods of functor?](https://discourse.julialang.org/t/how-to-get-methods-of-functor/101050)

<div class="topic-metadata">

**Author:** [@andrey2185](https://discourse.julialang.org/u/andrey2185)\
**Replies:** 1\
**Last updated:** [July 1, 2023, 1:04pm UTC](https://discourse.julialang.org/t/how-to-get-methods-of-functor/101050 "2023-07-01T13:04:51Z")

</div>

How to get methods of functor? julia\> foo() = 2; julia\> foo(x) = x + 2; julia\> methods(foo) # 2 methods for generic function "foo": \[1\] foo() in Main at REPL\[21\]:1 \[2\] foo(x) in Main at REPL\[22\]:1 julia\> struct Foo x en…

---

## [How do I tell if an object is callable (a function-like object)?](https://discourse.julialang.org/t/how-do-i-tell-if-an-object-is-callable-a-function-like-object/100831)

<div class="topic-metadata">

**Author:** [@coldinjection](https://discourse.julialang.org/u/coldinjection)\
**Replies:** 15\
**Last updated:** [June 26, 2023, 9:34pm UTC](https://discourse.julialang.org/t/how-do-i-tell-if-an-object-is-callable-a-function-like-object/100831 "2023-06-26T21:34:49Z")

</div>

Say there’s a type T, how can I tell if function (t::T)()… is defined? Is there any way other than trying t() and catching a MethodError?

---

## [Memory allocation issue of a Euler solver implementation](https://discourse.julialang.org/t/memory-allocation-issue-of-a-euler-solver-implementation/96086)

<div class="topic-metadata">

**Author:** [@stevengogogo](https://discourse.julialang.org/u/stevengogogo)\
**Replies:** 2\
**Last updated:** [March 14, 2023, 8:47pm UTC](https://discourse.julialang.org/t/memory-allocation-issue-of-a-euler-solver-implementation/96086 "2023-03-14T20:47:31Z")

</div>

Hello all, I am implementing ODE solvers for a class assignment. Unfortunately, there is a memory allocation problem with my script, and the performance is not optimal. Problem Description The implementation uses the f…

---

## [Question about functors and closures (I think 😅), with an example, but really a general Q](https://discourse.julialang.org/t/question-about-functors-and-closures-i-think-with-an-example-but-really-a-general-q/88758)

<div class="topic-metadata">

**Author:** [@fins](https://discourse.julialang.org/u/fins)\
**Replies:** 27\
**Last updated:** [October 18, 2022, 7:54pm UTC](https://discourse.julialang.org/t/question-about-functors-and-closures-i-think-with-an-example-but-really-a-general-q/88758 "2022-10-18T19:54:48Z")

</div>

Hi, I’ve just been fiddling with some bits of code and am still a bit blown away by some julian’ language-constructs. I’ve been doing oo-programming, mainly, for a considerable timespan & my (purely ever academic) expos…

---

## [Shorthand syntax for defining functors](https://discourse.julialang.org/t/shorthand-syntax-for-defining-functors/88380)

<div class="topic-metadata">

**Author:** [@dylanxyz](https://discourse.julialang.org/u/dylanxyz)\
**Replies:** 17\
**Last updated:** [October 9, 2022, 4:11am UTC](https://discourse.julialang.org/t/shorthand-syntax-for-defining-functors/88380 "2022-10-09T04:11:21Z")

</div>

Currently, to define a function with a custom type in julia, we use functors: julia\> struct MyType \<: Function end julia\> (::MyType)() = println("Hello world!") julia\> (::MyType)(name) = println("Hello $(name)!") jul…

---

## [Functor preprocessing pattern](https://discourse.julialang.org/t/functor-preprocessing-pattern/86200)

<div class="topic-metadata">

**Author:** [@ctrebbau](https://discourse.julialang.org/u/ctrebbau)\
**Replies:** 7\
**Last updated:** [September 8, 2022, 1:18pm UTC](https://discourse.julialang.org/t/functor-preprocessing-pattern/86200 "2022-09-08T13:18:26Z")

</div>

I’m trying to adapt the preprocessing pattern showcased by https://github.com/jeremiedb here https://www.youtube.com/watch?v=dzChtn9WWT8 He basically creates a structure to store transformation functions and a functor…

---

## [Implementing the tensor algebra functor](https://discourse.julialang.org/t/implementing-the-tensor-algebra-functor/64433)

<div class="topic-metadata">

**Author:** [@choquet](https://discourse.julialang.org/u/choquet)\
**Replies:** 0\
**Last updated:** [July 10, 2021, 5:32pm UTC](https://discourse.julialang.org/t/implementing-the-tensor-algebra-functor/64433 "2021-07-10T17:32:28Z")

</div>

I’m trying to implement the free tensor algebra functor T: given a vector space V it creates another vector space T(V). This vector space T(V) has many nice properties, for example, T(V) is not just a vector space but al…

---

## [Differences between ParameterHandling and Functors](https://discourse.julialang.org/t/differences-between-parameterhandling-and-functors/63495)

<div class="topic-metadata">

**Author:** [@theogf](https://discourse.julialang.org/u/theogf)\
**Replies:** 0\
**Last updated:** [June 24, 2021, 12:03pm UTC](https://discourse.julialang.org/t/differences-between-parameterhandling-and-functors/63495 "2021-06-24T12:03:41Z")

</div>

Could someone tell me if I got the differences between ParameterHandling.jl and Functors.jl right? Both seem to allow to deconstruct/reconstruct a struct to extract arrays of parameters. The differences I see are : F…

---

## [Specify the type of function when it is a parameter of another function](https://discourse.julialang.org/t/specify-the-type-of-function-when-it-is-a-parameter-of-another-function/85724)

<div class="topic-metadata">

**Author:** [@rocco\_sprmnt21](https://discourse.julialang.org/u/rocco_sprmnt21)\
**Replies:** 4\
**Last updated:** [August 14, 2022, 6:56pm UTC](https://discourse.julialang.org/t/specify-the-type-of-function-when-it-is-a-parameter-of-another-function/85724 "2022-08-14T18:56:12Z")

</div>

Perhaps the question doesn’t matter much in practice or even makes little sense in theory. In which case, please explain the reasons in a simple way. Playing with the splitarray function, I wondered if and how it was po…

---

## [Search nested namedtuples by key](https://discourse.julialang.org/t/search-nested-namedtuples-by-key/84352)

<div class="topic-metadata">

**Author:** [@rocco\_sprmnt21](https://discourse.julialang.org/u/rocco_sprmnt21)\
**Replies:** 5\
**Last updated:** [July 18, 2022, 10:15am UTC](https://discourse.julialang.org/t/search-nested-namedtuples-by-key/84352 "2022-07-18T10:15:09Z")

</div>

using the Functor package I quickly found how to search by value type, but not by key. Is it possible to do this (ie search by key) in some way or with the help of another package? julia\> nt=(gr='a',f1=1, f2=(gr='b', f…

---

## [\[ANN\] FlexibleFunctors.jl: Functors with Per-Instance Parameters](https://discourse.julialang.org/t/ann-flexiblefunctors-jl-functors-with-per-instance-parameters/64935)

<div class="topic-metadata">

**Author:** [@sbuercklin](https://discourse.julialang.org/u/sbuercklin)\
**Replies:** 3\
**Last updated:** [December 9, 2021, 7:08am UTC](https://discourse.julialang.org/t/ann-flexiblefunctors-jl-functors-with-per-instance-parameters/64935 "2021-12-09T07:08:05Z")

</div>

FlexibleFunctors.jl provides a utility for destructuring, restructuring, and mapping operations over a flexible set of parameters for any type. Parameter tagging is flexible in its implementation, permitting either glob…

---

## [Function sub typing of Functors](https://discourse.julialang.org/t/function-sub-typing-of-functors/68658)

<div class="topic-metadata">

**Author:** [@jdlara-berkeley](https://discourse.julialang.org/u/jdlara-berkeley)\
**Replies:** 1\
**Last updated:** [September 23, 2021, 10:55pm UTC](https://discourse.julialang.org/t/function-sub-typing-of-functors/68658 "2021-09-23T22:55:14Z")

</div>

When defining a functor should the struct be subtyped from Function? For instance struct foo \<: Function a b end function (functor::foo)(x, y) return functor.a\*x + functor.b\*y end or just is fine? struct…

---

## [Using functors for sparse Jacobian evaluations](https://discourse.julialang.org/t/using-functors-for-sparse-jacobian-evaluations/64111)

<div class="topic-metadata">

**Author:** [@jdlara-berkeley](https://discourse.julialang.org/u/jdlara-berkeley)\
**Replies:** 2\
**Last updated:** [July 6, 2021, 12:13am UTC](https://discourse.julialang.org/t/using-functors-for-sparse-jacobian-evaluations/64111 "2021-07-06T00:13:38Z")

</div>

I am trying to use ForwardDiff to calculate the Jacobian of a function so that I can reuse the resulting Jacobian function and use it as an input for several packages. For instance, pass it to NLsolve and later use it in…

---

## [Functors and allocations](https://discourse.julialang.org/t/functors-and-allocations/62547)

<div class="topic-metadata">

**Author:** [@vettert](https://discourse.julialang.org/u/vettert)\
**Replies:** 4\
**Last updated:** [June 8, 2021, 5:04am UTC](https://discourse.julialang.org/t/functors-and-allocations/62547 "2021-06-08T05:04:04Z")

</div>

I would like define a custom type carrying parameters for a function inside it and then I would like to update the parameters of the function. The problem is that I don’t know the number of parameters a priori (it shall…

---

## [How to understand Flux.functor?](https://discourse.julialang.org/t/how-to-understand-flux-functor/57906)

<div class="topic-metadata">

**Author:** [@pilgrimygy](https://discourse.julialang.org/u/pilgrimygy)\
**Replies:** 2\
**Last updated:** [March 25, 2021, 5:51am UTC](https://discourse.julialang.org/t/how-to-understand-flux-functor/57906 "2021-03-25T05:51:33Z")

</div>

Dear Community, I got a question about functor usage in Flux.jl. When I read the DQN code in ReinforcementLearningZoo, I confused the usage of the functor: Flux.functor(x::DQNLearner) = (Q = x.approximator, Qₜ = x.targe…

---

## [Why is the function of a callable object (Functor) allocating?](https://discourse.julialang.org/t/why-is-the-function-of-a-callable-object-functor-allocating/57773)

<div class="topic-metadata">

**Author:** [@zsoerenm](https://discourse.julialang.org/u/zsoerenm)\
**Replies:** 1\
**Last updated:** [March 23, 2021, 8:21am UTC](https://discourse.julialang.org/t/why-is-the-function-of-a-callable-object-functor-allocating/57773 "2021-03-23T08:21:10Z")

</div>

I’m experimenting with functors. I noticed that when I pass an array to the functor, that it is allocating memory even if it should be possible without memory allocation. Here is a simplified version: struct Foo end (:…

---

## [Define data-dependent function, various ways](https://discourse.julialang.org/t/define-data-dependent-function-various-ways/48988)

<div class="topic-metadata">

**Author:** [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Replies:** 34\
**Last updated:** [November 2, 2020, 1:14pm UTC](https://discourse.julialang.org/t/define-data-dependent-function-various-ways/48988 "2020-11-02T13:14:50Z")

</div>

This is a topic that is frequently raised here (I have asked this before). The problem is that of defining a function that will be input as a parameter for a solver, but the function depends on data while the function ca…

---

## [Combining functors, broadcasting, and pipes](https://discourse.julialang.org/t/combining-functors-broadcasting-and-pipes/48691)

<div class="topic-metadata">

**Author:** [@klaff](https://discourse.julialang.org/u/klaff)\
**Replies:** 2\
**Last updated:** [October 20, 2020, 4:27pm UTC](https://discourse.julialang.org/t/combining-functors-broadcasting-and-pipes/48691 "2020-10-20T16:27:12Z")

</div>

I’ve got another behavior I don’t quite understand. Here’s an MWE: begin struct MyStruct x end function(ms::MyStruct)(y) ms.x\*y end end ms1=MyStruct(2) ms1(2) # works 2 |\> ms1 # works ms1.((3,4)) # works b…

---

## [Functor usage for Optim.jl](https://discourse.julialang.org/t/functor-usage-for-optim-jl/45778)

<div class="topic-metadata">

**Author:** [@stevengogogo](https://discourse.julialang.org/u/stevengogogo)\
**Replies:** 4\
**Last updated:** [August 31, 2020, 3:32pm UTC](https://discourse.julialang.org/t/functor-usage-for-optim-jl/45778 "2020-08-31T15:32:07Z")

</div>

Dear Community, I got a question about functor usage with Optim.jl. I’m currently writing a Julian package for biological modeling. To organize parameters of the biological process, I chose function-like object (funct…

---

## [Why is functor slower than eval'ed function?](https://discourse.julialang.org/t/why-is-functor-slower-than-evaled-function/43840)

<div class="topic-metadata">

**Author:** [@kevbonham](https://discourse.julialang.org/u/kevbonham)\
**Replies:** 8\
**Last updated:** [July 29, 2020, 2:48pm UTC](https://discourse.julialang.org/t/why-is-functor-slower-than-evaled-function/43840 "2020-07-29T14:48:25Z")

</div>

I have a situation where I’d like to build some functions based on different inputs - using a callable function seems really clear to me, and has the functionality I want. I’d rather not use eval and other metaprogrammin…

---

## [Flux.functor](https://discourse.julialang.org/t/flux-functor/37334)

<div class="topic-metadata">

**Author:** [@erlebach](https://discourse.julialang.org/u/erlebach)\
**Replies:** 1\
**Last updated:** [April 10, 2020, 8:37pm UTC](https://discourse.julialang.org/t/flux-functor/37334 "2020-04-10T20:37:51Z")

</div>

Could somebody please explain the use of Flux.functor? Functors return functions, but I do not understand the use case. I would also like to understand the use of @functor when using Flux. I tried the following and it w…

---

## [How are functors useful?](https://discourse.julialang.org/t/how-are-functors-useful/24110)

<div class="topic-metadata">

**Author:** [@tk3369](https://discourse.julialang.org/u/tk3369)\
**Replies:** 26\
**Last updated:** [March 23, 2020, 5:03pm UTC](https://discourse.julialang.org/t/how-are-functors-useful/24110 "2020-03-23T17:03:35Z")

</div>

It’s interesting that a method can be defined and attached to a type as described in the documentation about functors. I’m curious how it is ever useful though. Why not just define a regular function so it has a name t…

---

## [Question about Functors](https://discourse.julialang.org/t/question-about-functors/33876)

<div class="topic-metadata">

**Author:** [@tbeason](https://discourse.julialang.org/u/tbeason)\
**Replies:** 7\
**Last updated:** [January 28, 2020, 4:41pm UTC](https://discourse.julialang.org/t/question-about-functors/33876 "2020-01-28T16:41:44Z")

</div>

I am trying to solve an economic model. The algorithm involves an iterative two-step procedure, like a back-and-forth optimization. There are lots of inputs and moving parts. I created a struct to keep track of it all. W…

---

## [Documenting a functor / callable struct](https://discourse.julialang.org/t/documenting-a-functor-callable-struct/8444)

<div class="topic-metadata">

**Author:** [@jmert](https://discourse.julialang.org/u/jmert)\
**Replies:** 5\
**Last updated:** [January 18, 2018, 1:47pm UTC](https://discourse.julialang.org/t/documenting-a-functor-callable-struct/8444 "2018-01-18T13:47:26Z")

</div>

I’m interested in providing a docstring for a functor / callable struct I’m using, but I have to questions about that: How do you correctly query for the doc string at the REPL? The ?MyFunc (assuming code below) obviou…

---

## [Functor abstract types](https://discourse.julialang.org/t/functor-abstract-types/4887)

<div class="topic-metadata">

**Author:** [@juliohm](https://discourse.julialang.org/u/juliohm)\
**Replies:** 11\
**Last updated:** [November 7, 2017, 5:10am UTC](https://discourse.julialang.org/t/functor-abstract-types/4887 "2017-11-07T05:10:56Z")

</div>

Given a concrete type, one can define functor-like methods with: struct Foo end (f::Foo)(x) = 2x and use the object as a function: f = Foo() f(1) This doesn’t work with abstract types, however; even though they suppo…

---

## [Help defining Functor type](https://discourse.julialang.org/t/help-defining-functor-type/4509)

<div class="topic-metadata">

**Author:** [@juliohm](https://discourse.julialang.org/u/juliohm)\
**Replies:** 8\
**Last updated:** [June 28, 2017, 10:23am UTC](https://discourse.julialang.org/t/help-defining-functor-type/4509 "2017-06-28T10:23:28Z")

</div>

I am almost there, but this is my first time using StaticArrays.jl and I am not sure I got the concepts right: using StaticArrays: SMatrix """ EllipsoidDistance(\[a₁, a₂, ...\], \[θ₁, θ₂, ...\]) A distance defined by …
