A couple of shortcut methods on Func

This commit is contained in:
alari 2019-08-14 16:33:25 +03:00
parent 70dae6edca
commit cf36fdb00e

View File

@ -49,6 +49,7 @@ abstract class MonadicalEitherArrow[E <: Throwable] {
* @tparam B Successful result type
*/
abstract class Func[A, B] {
f
/**
* Run the func on input, using the given monad.
@ -76,6 +77,30 @@ abstract class MonadicalEitherArrow[E <: Throwable] {
*/
def apply[F[_]: Monad](input: A): EitherT[F, E, B]
/**
* Shortcut for function composition
*
* @param other Other function to run after
* @tparam C Resulting input type
* @return Composed function
*/
def on[C](other: Func[C, A]): Func[C, B] =
catsMonadicalEitherArrowChoice.compose(this, other)
/**
* Convert this Func into another one, lifting the error
*
* @param m Another instance of MonadicalEitherArrow
* @param convertE Convert error
* @tparam EE Error type
* @return Converted function
*/
def to[EE <: Throwable](m: MonadicalEitherArrow[EE])(implicit convertE: E EE): m.Func[A, B] =
new m.Func[A, B] {
override def apply[F[_]: Monad](input: A): EitherT[F, EE, B] =
f[F](input).leftMap(convertE)
}
/**
* Converts this Func to Kleisli, using MonadError to execute upon and to lift errors into.
*