Stream: helpdesk (published)

Topic: Create 0-kwargs object


view this post on Zulip Timothy (Apr 19 2022 at 09:04):

Hey, I'm trying to store a "0 kwargs" object. I.e. the result of ((;k...) -> k)(). I see the type is Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}(), but that seems to be uninstantiable. The closest I could get was Base.Pairs(NamedTuple(),()) but that gives Base.Pairs{Union{}, ...instead of `Base.Pairs{Symbol, ....

view this post on Zulip Sebastian Pfitzner (Apr 19 2022 at 09:12):

Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}(NamedTuple(),()) works, no?

view this post on Zulip Takafumi Arakaki (tkf) (Apr 19 2022 at 09:16):

It's an immutable (and also is a singleton). So, why not just do const NOKWARGS = ((;k...) -> k)() and use it where you need it?


Last updated: Oct 02 2023 at 04:34 UTC