Two anonymous functions in one
Elixir has anonymous functions, and function pattern matching, and to accommodate the two concepts the language has the facility to do both at the same time.
alphaIndex = fn ("a") -> 0; ("b") -> 1; (letter) -> :unknown end
alphaIndex.("a")
# returns 0
alphaIndex.("b")
# returns 1
alphaIndex.("c")
# returns :unknown
Tweet