Skip to content

Nested Optionals seem to be difficult to do #594

Answered by williamboman
jay-babu asked this question in Q&A
Discussion options

You must be logged in to vote

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:

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)

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@jay-babu
Comment options

@jay-babu
Comment options

Answer selected by jay-babu
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants