Using pattern matching to compare two strings
Ryan Will
Posted on January 15, 2020
Elixir’s pattern matching feature is the gift that keeps on giving. I love this neat trick to check if two strings are the same. It is an easy way to check if a password and password confirmation match.
def passwords_match?(password, password), do: true
def passwords_match?(_, _), do: false
passwords_match?("password", "password") # true
passwords_match?("password", "notpassword") # false
💖 💪 🙅 🚩
Ryan Will
Posted on January 15, 2020
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.