Last active
August 29, 2015 14:05
-
-
Save no-longer-on-githu-b/47033a41be64a9f44a19 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
import invalid._ | |
sealed abstract class UserValidationError | |
case object FirstNameEmpty extends UserValidationError | |
case object LastNameEmpty extends UserValidationError | |
def createUser(saveUser: User => UserID)(firstName: String, lastName: String) = | |
validate( | |
firstName.isEmpty -> FirstNameEmpty, | |
lastName.isEmpty -> LastNameEmpty | |
) { User(firstName, lastName) } map saveUser |
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
import scalaz.{\/, \/-, -\/} | |
package object invalid { | |
def validate[E, R](pairs: (Boolean, E)*)(otherwise: => R): Set[E] \/ R = | |
if (pairs.exists(_._1)) -\/(pairs.map(_._2).toSet) else \/-(otherwise) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment