Skip to content

Instantly share code, notes, and snippets.

@Tombarr
Created January 8, 2019 01:57
Show Gist options
  • Save Tombarr/83b63976bbd77c9d295ca667ba6f0197 to your computer and use it in GitHub Desktop.
Save Tombarr/83b63976bbd77c9d295ca667ba6f0197 to your computer and use it in GitHub Desktop.
Basic Elixir pattern matching
# is it assignment?
all_systems = :go
# not quite
:go = all_systems
# alas age is but a number
tom = %{name: "Tom", age: 25}
%{age: num} = tom # 25
# there's no truth in matches
1 = 1 # 1
1 + 1 = 2 # CompileError
1 + 1 = 2 # MatchError
# except when you find your one, true match
[the_one | everything_else] = [true, false, false]
the_one = true # true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment