Stream: helpdesk (published)

Topic: functions and singletons as functions


view this post on Zulip Jeffrey Sarnoff (May 15 2021 at 18:13):

These two provide the same "functionality"

fna(x) = true
struct fnb end
fnb(x) = true

Is it possible to dispatch in a way that catches both?

view this post on Zulip Fredrik Ekre (May 15 2021 at 18:16):

You can define

struct fnb <: Function
end

and dispatch on ::Function.

view this post on Zulip Jeffrey Sarnoff (May 15 2021 at 18:28):

great and good to know

view this post on Zulip Rafael Fourquet (May 16 2021 at 06:15):

Sometimes Base.Callable == Union{Function,Type}is also used for this purpose.


Last updated: Oct 02 2023 at 04:34 UTC