loading...

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 Nov 13 '19

Apples announces new 16-inch Macbook Pro

Discussion thread for the new Macbook Pro thread

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

Night owl? 🦉

dev.to now has a dark version (in public beta).

Go to the "misc" section of your settings and select night theme ❤️