Skip to content

How to provide default value for fun arg #1642

Answered by vkleen
q0w asked this question in Q&A
Discussion options

You must be logged in to vote

There aren't default values for functions per se in Nickel. Two options come to mind. First, you can do the Nix thing and take a record as the single argument. In this record, you can have default values:

let install_gh_release = fun { name, repo, tag, platform ? "<default>" } => ...

The second, and the one that I would recommend, is not using a function to generate this data at all, but instead encode it as a recursively defined record with some fields left to be merged in. Fields that should end up in the final configuration can be marked as not_exported to hide them from serialization in simple cases. Sometimes it's more comfortable to have a dedicated output attribute. For example,

l…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@q0w
Comment options

Comment options

You must be logged in to vote
1 reply
@q0w
Comment options

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