Created
February 26, 2021 19:28
-
-
Save deanwampler/da96abae8c95f8443959e677824119a9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
case class User(name: String, password: String) | |
def checkName(user: User): Either[String,User] = | |
if (user.name.isEmpty) Left("Empty name") | |
else Right(user) | |
def checkPassword(user: User): Either[String,User] = | |
if (user.password.length < 8) Left("Password needs 8+ characters") | |
else Right(user) | |
Seq(User("", "12345678"), User("Dean", "1234"), User("Dean", "12345678")).map { | |
user => for { | |
_ <- checkName(user) | |
u <- checkPassword(user) | |
} yield u | |
} // List(Left(Empty name), Left(Password needs 8+ characters), Right(User(Dean,12345678))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment