Skip to content

Instantly share code, notes, and snippets.

@jferris
Created November 30, 2017 20:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jferris/937a7714ff09cd2b539e4622f993a7fd to your computer and use it in GitHub Desktop.
Save jferris/937a7714ff09cd2b539e4622f993a7fd to your computer and use it in GitHub Desktop.
EitherT, partially applied
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)
}
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