mirror of
https://github.com/fluencelabs/codec
synced 2025-04-25 14:52:14 +00:00
Compare commits
1 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
cf36fdb00e |
@ -49,6 +49,7 @@ abstract class MonadicalEitherArrow[E <: Throwable] {
|
|||||||
* @tparam B Successful result type
|
* @tparam B Successful result type
|
||||||
*/
|
*/
|
||||||
abstract class Func[A, B] {
|
abstract class Func[A, B] {
|
||||||
|
f ⇒
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Run the func on input, using the given monad.
|
* 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]
|
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.
|
* Converts this Func to Kleisli, using MonadError to execute upon and to lift errors into.
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user