Skip to content

Instantly share code, notes, and snippets.

@labra
Created August 5, 2016 21:49
Show Gist options
  • Save labra/862fc05caff0d4fa643de33b2bd633e8 to your computer and use it in GitHub Desktop.
Save labra/862fc05caff0d4fa643de33b2bd633e8 to your computer and use it in GitHub Desktop.
Example of catchWrong with a WriterEffect
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