Created
August 5, 2016 21:34
-
-
Save labra/e939f5aa82860548abbd5b59a37fc13e to your computer and use it in GitHub Desktop.
Example using eff-cats with catchWrong
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
package examples | |
import cats._, data._ | |
import org.atnos.eff._, all._ | |
import org.atnos.eff.syntax.all._ | |
object ExampleCatchWrong { | |
type E = String | |
type Comput = Validate[E, ?] |: NoEffect | |
type Check[A] = Eff[Comput,A] | |
def runCheck[A](c: Check[A]) = c.runNel.run | |
val comp1: Check[Int] = for { | |
_ <- wrong[Comput,E]("1") | |
_ <- wrong[Comput,E]("2") | |
} yield 0 | |
val handle: E => Check[Int] = { case e => pure(e.toInt) } | |
val comp2: Check[Int] = catchWrong(comp1)(handle) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment