Defining Multiple Clauses In An Anonymous Function
iex> my_function = fn
{:ok, x} -> "Everything is ok: #{x}"
{:error, x} -> "There was an error: #{x}"
end
#Function<6.52032458/1 in :erl_eval.expr/5>iex> my_function.({:ok, 123})
"Everything is ok: 123"
iex> my_function.({:error, "be warned"})
"There was an error: be warned"Last updated