Last active
August 29, 2015 14:08
-
-
Save erikkaplun/e37670c1dd35a839f83e 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
type Va[A] = Validation[String, A] | |
type VaNel[A] = ValidationNel[String, A] | |
import shapeless._, contrib.scalaz._, syntax.std.tuple._ | |
import syntax.std.function._, ops.function._ | |
import shapeless.ops.hlist._ | |
// for Kleisli and its >=> | |
implicit val vaBinding = new Bind[Va] { | |
def map[A, B](fa: Va[A])(f: A => B): Va[B] = fa.map(f) | |
def bind[A, B](fa: Va[A])(f: A => Va[B]): Va[B] = { | |
import scalaz.Validation.FlatMap._ | |
fa.flatMap(f) | |
} | |
} | |
type Vali[A, B] = Kleisli[Va, A, B] | |
val isIntegral = (msg: String) => Vali[Option[String], Option[Int]] { | |
case None => none[Int].success | |
case Some(x: String) => | |
Try(x.toInt) match { | |
case Success(i) => Some(i).success | |
case _ => msg.failure | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment