Application.get_env accept path instead of just a single key

105 views
Skip to first unread message

lostko...@gmail.com

unread,
Jul 5, 2022, 6:33:30 AM7/5/22
to elixir-lang-core
I just noticed that `Application.compile_env` accepts a path of keys besides a single key. `Application.get_env` doesn't seem to support that. Is there a reason for this difference? If not I'd like to see that possibility be added so their parameters are aligned.

José Valim

unread,
Jul 5, 2022, 6:37:02 AM7/5/22
to elixir-lang-core
Unfortunately Application.get_env accepted anything as key in previous versions. It has been deprecated but it means we cannot accept paths for now.

On Tue, Jul 5, 2022 at 12:33 PM lostko...@gmail.com <lostko...@gmail.com> wrote:
I just noticed that `Application.compile_env` accepts a path of keys besides a single key. `Application.get_env` doesn't seem to support that. Is there a reason for this difference? If not I'd like to see that possibility be added so their parameters are aligned.

--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/e74a7739-e11d-4aad-8550-b17fd6839a2bn%40googlegroups.com.

luk...@niemier.pl

unread,
Jul 27, 2022, 6:01:40 AM7/27/22
to elixir-lang-core
Maybe we could have `Application.get_in_env` that would operate like `get_in/2` on the return value of `Application.get_env/2`.

José Valim

unread,
Jul 27, 2022, 6:05:08 AM7/27/22
to elixir-lang-core
You can already do:

    Application.get_env(app, key1)[key2][key3]

Or pipe to get_in afterwards.

The reason why we added paths to compile_env is mostly because we need to know the path in order to know what parts of the environment has become stale, but otherwise we would not have added such feature. So you can achieve similar to get_in/3 today, the only reason for it to also support paths is consistency.

Yordis Prieto

unread,
Aug 12, 2022, 10:04:13 PM8/12/22
to elixir-lang-core
Interesting ...  the `Application.compile_env` spoiled me though, has been long enough where I wouldn't mind having an `Application.get_in_env`, not necessary, but honestly really handy.
Reply all
Reply to author
Forward
0 new messages