Weird Operator Uses in Elixir
= is match, not assignment (sometimes they're equivalent)
<> is string concatenation
[a | b] is a pipe used within squares and appends the left hand side to the right hand side when the right hand side is a list.
++ is an append operator for lists
[1, 2, 3] ++ [4] == [1, 2, 3, 4]
-- is a subtraction operator for lists.
[1, 2, 3] -- [1, 2] == [3]
in checks to see if an element is included in a list.
1 in [1] == true
=== works with numbers and returns false when comparing numbers of different types that would otherwise be equivalent.
(1 === 1.0) == false; (1 == 1.0) == true
^ is the pin operator, it switches a variable from assignable to matchable.
iex > a = 1; {^a, b} = {1, 2};
{1, 2}
iex > a = 1; {^a, b} = {2, 2};
** (MatchError) no match of right hand side value: {2, 2}
iex > a = 1; {a, b} = {2, 2};
{2, 2}
Tweet