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?

view this post on Zulip Timothy (Apr 19 2022 at 10:15):

Sebastian Pfitzner said:

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

Ah, that does it. I just hadn't figured out the arguments needed to construct it. Thanks :)

view this post on Zulip Notification Bot (Apr 19 2022 at 10:16):

Timothy has marked this topic as resolved.


Last updated: Nov 22 2024 at 04:41 UTC