Pattern Matching In Anonymous Functions
> handle_result = fn
{:ok, result} -> IO.puts "The result is #{result}"
:error -> IO.puts "Error: couldn't find anything"
end
#Function<6.50752066/1 in :erl_eval.expr/5>
> Map.fetch(%{a: 1}, :a) |> handle_result.()
The result is 1
:ok
> Map.fetch(%{a: 1}, :b) |> handle_result.()
Error: couldn't find anything
:okLast updated