Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optional keys and expansions #7

Open
neverfox opened this issue Apr 2, 2016 · 1 comment
Open

Optional keys and expansions #7

neverfox opened this issue Apr 2, 2016 · 1 comment

Comments

@neverfox
Copy link

neverfox commented Apr 2, 2016

It's a pretty common case that I want optional config keys because the function that will eventually take in that config has its own fallbacks. For example, with langhor (library for RabbitMQ), the connect function accepts a map of connection parameters, e.g. :host, :port, :username etc., all of which are optional and have defaults if they're not provided. So it makes sense for me to model my config after the map the connect function accepts and exploit the built-in fallbacks. Furthermore, when I do want to set a value, I want to do it with environment variables. However, there doesn't seem to be a way to tell this library to optionally include a key based on whether or not an environment variable expansion is successful. The only way to avoid an exception is to provide a non-nil default, but that would require me to essentially duplicate the defaults that are already handled by langhor. Would it be possible to have some kind of reader conditional for optional configuration within a profile (perhaps where nil as a value drops the key)?

@hlship
Copy link
Collaborator

hlship commented Apr 15, 2016

It's tricky, because the reader form will produce a value, and the value may be nil, but it can't affect the key (that ship has sailed).

In your code that invokes langhor, you could easily drop keys with nil values (medley has a function that can do this easily).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants