Using pattern matching to compare two strings

twitter logo github logo Originally published at til.ryanwill.dev on ・1 min read

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
twitter logo DISCUSS
Classic DEV Post from Aug 30 '19

SELECT Post FROM Stack Overflow Questions WHERE Topic = "git" ORDER BY Votes DESC;

Ryan Will profile image
Cultivating software. Aprendiendo español. Piensa más en lo que te fascina.

Do you prefer sans serif over serif?

You can change your font preferences in the "misc" section of your settings. ❤️