Code Golf in Elixir

Elixir has some great short forms of functions:

This is the identity function:

& &1

You can use this to turn a list into a map of counts:

~w[a b c]a |> Map.new(&{&1, 0})

The if statement is an expression and will return nil for the else clause

a = if foo == "hello", do: "yes", else: nil end

There is also an unless that is the reverse of if

Leave a comment