Created
August 5, 2016 21:49
-
-
Save labra/862fc05caff0d4fa643de33b2bd633e8 to your computer and use it in GitHub Desktop.
Example of catchWrong with a WriterEffect
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._ | |
import cats.implicits._ | |
object ExampleCatchWrong { | |
type E = String | |
type Comput = Validate[E, ?] |: Writer[E,?] |: NoEffect | |
type Check[A] = Eff[Comput,A] | |
def runCheck[A](c: Check[A]) = c.runNel.runWriter.run | |
val comp1: Check[Int] = for { | |
_ <- wrong[Comput,E]("1") | |
_ <- wrong[Comput,E]("2") | |
} yield 0 | |
val handle: E => Check[Int] = { case e => tell[Comput,E](e).as(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