Skip to content

Instantly share code, notes, and snippets.

@hexx
Created September 17, 2012 18:16
Show Gist options
  • Save hexx/3738873 to your computer and use it in GitHub Desktop.
Save hexx/3738873 to your computer and use it in GitHub Desktop.
Start Scalaz2 Exercise2
def get[K, V](k: K)(m: Map[K, V]): String \?/ V =
try {
m(k).success
} catch {
case e: Throwable => e.getMessage.failure
}
def user(m: Map[String, String]): NonEmptyList[String] \?/ User =
(get("id")(m).toValidationNEL |@| get("age")(m).flatMap(parseInt).toValidationNEL)((id, age) => User(id, age.toInt))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment