Warning: this is an attempt to be clever. I am aware that I probably should just leave it readable, but that doesn't mean I don't want to know how to be clever :-P
I have something like this (contrived example):
def glue(%{"alpha" => alpha, "beta" => beta}) do
cond do
alpha && beta ->
alpha <> beta
alpha ->
IO.puts("oops, you forgot to give me alpha!")
true ->
IO.puts("oops, you forgot to give me beta!")
end
end
but would like to instead have:
def glue(%{"alpha" => alpha, "beta" => beta}) do
cond do
alpha && beta ->
alpha <> beta
true ->
something
|> need_field()
end
end
defp need_field(something) do
IO.puts("oops, you forgot to give me " <> something)
end
Is there a clever way to get the name of the empty variable?
I was thinking along the lines of somehow using alpha || beta to get the populated one, then print the name of the other one, but I can't quite seem to get there.
alpha && betareturns false? Will they be nil, or can they be false? - Steve Pallen