Created
October 26, 2015 20:03
-
-
Save milosgajdos/13ed25898d35c68a07ec to your computer and use it in GitHub Desktop.
Find out if all elements in tuple have the same value
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
iex(5)> foo = {1,2,3} | |
{1, 2, 3} | |
iex(6)> bar = {1,1,1} | |
{1, 1, 1} | |
iex(7)> {item, item, item} = foo | |
** (MatchError) no match of right hand side value: {1, 2, 3} | |
iex(7)> {item, item, item} = bar | |
{1, 1, 1} | |
iex(8)> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is also great to show the difference between normal vars, underscored vars and
_
as special case:Although variables starting with an underscore are not intended to be used, they constitute real variables during pattern matching which must take the same value. In contrast,
_
is a "real" wildcard.This makes, of course, all perfect sense, I just wanted to write it down while re-discovering it 😉