Nested Optionals seem to be difficult to do #594
-
Hello, I needed to some nested Optionals as there could be multiple nil values. I was wondering if there was an easier way to accomplish the below. Still getting used to this library, but definitely makes my life easier. local default_handler = Optional.of_nilable(handlers[1])
:or_(_.always(Optional.of_nilable(default_setup(installed_sources)))) Thanks! |
Beta Was this translation helpful? Give feedback.
Answered by
williamboman
Oct 25, 2022
Replies: 1 comment 2 replies
-
Hey! So both the functional and optional modules are technically not part of the public Lua API, so use should be done with care (although I don't think it'll be an issue). Not sure what values your example involves, but if local default_handler = Optional.of_nilable(handlers[1]):or_else_get(function ()
return default_setup(installed_sources)
end)
-- but you probably dont need to use the Optional interface
local default_handler = handlers[1] or default_setup(installed_sources) |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
jay-babu
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey! So both the functional and optional modules are technically not part of the public Lua API, so use should be done with care (although I don't think it'll be an issue). Not sure what values your example involves, but if
default_setup()
never returns nil, I'd probably unwrap the optional immediately like so: