I've got the following Elixir code:
defmodule Envvar do
def exists?(env) do :os.getenv(env) != false end
def get(env) do
if exists?(env) do
{env, :os.getenv(env)}
else
{env, nil}
end
end
end
Two things:
- Am I using the
?
correctly here? I'm assuming that any predicate function should have the?
on the end of the name by convention. - Is there a way to code the get function as a pattern match rather than a
if
/else
? I'm asking here because I'm guessing that a pattern match would be more idiomatic Elixir code.