Today I Learned

hashrocket A Hashrocket project

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
See More #elixir TILs
Looking for help? At Hashrocket, we 💜 Elixir! From our many Elixir client projects, to sponsoring the Chicago Elixir Meetup, to the source code for this application, we are invested in this community. Contact us today to talk about your Elixir project.