Skip to content

Instantly share code, notes, and snippets.

@no-longer-on-githu-b
Created August 8, 2014 11:04
Show Gist options
  • Save no-longer-on-githu-b/d77e22ad5c47c4a17eab to your computer and use it in GitHub Desktop.
Save no-longer-on-githu-b/d77e22ad5c47c4a17eab to your computer and use it in GitHub Desktop.
def saveUser(ds: DataSource)(user: User): UserID = {
// blabla
}
abstract class UserValidationError
case object FirstNameEmpty extends UserValidationError
case object LastNameEmpty extends UserValidationError
def createUser(saveUser: User => UserID)(firstName: String, lastName: String): ValidationNel[UserValidationError, UserID] = {
def validateFirstName(name: String) = if (name.isEmpty) FirstNameEmpty.fail else name.success
(validateFirstName ⊛ validateLastName)(User(_, _)) map saveUser
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment