Created
November 30, 2017 20:24
-
-
Save jferris/937a7714ff09cd2b539e4622f993a7fd to your computer and use it in GitHub Desktop.
EitherT, partially applied
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
import cats.{Applicative, Functor} | |
import cats.data.EitherT | |
import scala.language.higherKinds | |
object EitherTF { | |
def apply[F[_], A]: EitherTPartiallyApplied[F, A] = | |
new EitherTPartiallyApplied[F, A] | |
} | |
class EitherTPartiallyApplied[F[_], A](val dummy: Boolean = true) | |
extends AnyVal { | |
def apply[B](value: F[Either[A, B]]): EitherT[F, A, B] = EitherT(value) | |
def right[B](fb: F[B])(implicit f: Functor[F]): EitherT[F, A, B] = | |
EitherT.right[A](fb) | |
def leftT[B](a: A)(implicit f: Applicative[F]): EitherT[F, A, B] = | |
EitherT.leftT[F, B](a) | |
def fromEither[B](either: Either[A, B])( | |
implicit f: Applicative[F]): EitherT[F, A, B] = | |
EitherT.fromEither[F](either) | |
} |
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
import cats.data.EitherT | |
import scala.concurrent.Future | |
package object example { | |
sealed trait ApiError | |
case object ServerError extends ApiError | |
case object AccessDenied extends ApiError | |
type ApiResponse[A] = EitherT[Future, ApiError, A] | |
val ApiResponse = EitherT[Future, ApiError] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment