Created
July 27, 2017 05:29
-
-
Save edmundnoble/b99aaadf454465142c61222c54468f18 to your computer and use it in GitHub Desktop.
Lifting instance
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
trait EitherTInstances { | |
implicit final def eitherMonadLayerControl[M[_], E] | |
(implicit M: Monad[M]): MonadLayerControl.Aux[EitherTC[M, E]#l, M, EitherC[E]#l] = { | |
new MonadLayerControl[EitherTC[M, E]#l, M] { | |
type State[A] = E Either A | |
val outerInstance: Monad[CurryT[EitherTCE[E]#l, M]#l] = | |
EitherT.catsDataMonadErrorForEitherT | |
val innerInstance: Monad[M] = M | |
def layerMapK[A](ma: EitherT[M, E, A])(trans: M ~> M): EitherT[M, E, A] = EitherT(trans(ma.value)) | |
def layer[A](inner: M[A]): EitherT[M, E, A] = EitherT.right(inner) | |
def restore[A](state: Either[E, A]): EitherT[M, E, A] = EitherT.fromEither[M](state) | |
def layerControl[A](cps: (EitherTC[M, E]#l ~> (M of EitherC[E]#l)#l) => M[A]): EitherT[M, E, A] = { | |
EitherT.right(cps(new (EitherTC[M, E]#l ~> (M of EitherC[E]#l)#l) { | |
def apply[X](fa: EitherT[M, E, X]): M[Either[E, X]] = fa.value | |
})) | |
} | |
def zero[A](state: Either[E, A]): Boolean = state.isLeft | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment