import scalaz._
import Scalaz._
import effectie.scalaz.Effectful._
import effectie.scalaz._
import effectie.scalaz.EitherTSupport._
trait Something[F[_]] {
def foo(a: Int): F[String \/ Int]
def bar(a: String \/ Int): F[String \/ Int]
}
object Something {
def apply[F[_]: Something]: Something[F] =
implicitly[Something[F]]
implicit def something[F[_]: Fx: Monad]: Something[F] =
new SomethingF[F]
final class SomethingF[F[_]: Fx: Monad]
extends Something[F] {
def foo(a: Int): F[String \/ Int] = (for {
x <- a.rightTF[F, String]
y <- (x + 10).rightTF[F, String]
y2 <- if (y > 100)
eitherTLeft[Int]("Error - Bigger than 100")
else
eitherTRightPure[String](y)
z <- effectOf(y2 + 100).rightT[String]
} yield z).run
def bar(a: String \/ Int): F[String \/ Int] = (for {
x <- a.eitherT[F]
y <- effectOf((x + 999).right[String]).eitherT
} yield y).run
}
}
import scalaz.effect._
Something[IO].foo(1).unsafePerformIO()
Something[IO].foo(10).unsafePerformIO()
Something[IO].bar(1.right[String]).unsafePerformIO()
Something[IO].bar("No number".left[Int]).unsafePerformIO()