I Love you Match Operator - to Elixir (Episode 3)

You know the cool thing about Elixir? The Pattern Matching. I know other languages also providing this stuff but the way elixir provide us the pattern matching is not just cool but also easy to use. Here is the love at first sight. When I first see Elixir I just fall in love with this just because of this Match Operator...


Equals is not just for equality
In Elixir the equals sign isn't just about assigning things to make the computer remember them, but it can also be used for matching things. You can think of it like the equals sign in mathematics, where the left-hand-side must equal (or "match") the right-hand-side for the equation to be valid. 
iex> 5 = 2 + 2
** (MatchError) no match of right hand side value: 4
Unlike the famous Mr. Winston Smith, Elixir cannot ever be coerced into disbelieving reality. Here, Elixir is telling us that 2 + 2 is indeed not 5. In Elixir, the left-hand-side has to evaluate to the same as the right-hand-side. This will make the computer happy:
iex> 4 = 2 + 2
4
Similarly, having two identical strings on either side of the equals sign will also make the computer happy:
iex> "dog" = "dog"
"dog"
Here is the link of official documentation https://elixir-lang.org/getting-started/pattern-matching.html

So guys hope you like this feature. Today just have no mode to type more so ending this stuff here. In my next episode I explain more about Pattern Matching. Stay tuned.

For complete blog story To Elixir with umiExpress Click Here