Skip to content

Commit

Permalink
avoid org.atnos.eff.all
Browse files Browse the repository at this point in the history
  • Loading branch information
xuwei-k committed Aug 7, 2023
1 parent d6a5331 commit db8dd79
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ object either extends either
trait either {

def fromDisjunction[R, E, A](ea: E \/ A)(implicit member: Either[E, *] |= R): Eff[R, A] =
org.atnos.eff.all.fromEither(ea.toEither)
org.atnos.eff.either.fromEither(ea.toEither)

def runDisjunction[R, U, E, A](r: Eff[R, A])(implicit m: Member.Aux[Either[E, *], R, U]): Eff[U, E \/ A] =
org.atnos.eff.all.runEither(r).map(_.fold(\/.left, \/.right))
org.atnos.eff.either.runEither(r).map(_.fold(\/.left, \/.right))

/** run the Either effect, yielding E Either A and combine all Es */
def runDisjunctionCombine[R, U, E, A](r: Eff[R, A])(implicit m: Member.Aux[Either[E, *], R, U], s: Semigroup[E]): Eff[U, E \/ A] =
org.atnos.eff.all.runEitherCombine(r)(m, catsSemigroup(s)).map(_.fold(\/.left, \/.right))
org.atnos.eff.either.runEitherCombine(r)(m, catsSemigroup(s)).map(_.fold(\/.left, \/.right))

/** catch and handle a possible left value. The value is the combination of all failures in case of an applicative */
def catchLeftCombine[R, E, A](r: Eff[R, A])(handle: E => Eff[R, A])(implicit member: Either[E, *] /= R, s: Semigroup[E]): Eff[R, A] =
org.atnos.eff.all.catchLeftCombine(r)(handle)(member, catsSemigroup(s))
org.atnos.eff.either.catchLeftCombine(r)(handle)(member, catsSemigroup(s))

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ object eval extends eval
trait eval {

def attemptEvalDisjunction[R, U, A](r: Eff[R, A])(implicit m: Member.Aux[Eval, R, U]): Eff[U, Throwable \/ A] =
org.atnos.eff.all.attemptEval(r).map(_.fold(\/.left, \/.right))
org.atnos.eff.eval.attemptEval(r).map(_.fold(\/.left, \/.right))

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ object safe extends safe
trait safe {

def runSafeDisjunction[R, U, A](r: Eff[R, A])(implicit m: Member.Aux[Safe, R, U]): Eff[U, (Throwable \/ A, List[Throwable])] =
org.atnos.eff.all.runSafe(r).map(_.leftMap(_.fold(\/.left, \/.right)))
org.atnos.eff.SafeEffect.runSafe(r).map(_.leftMap(_.fold(\/.left, \/.right)))

def execSafeDisjunction[R, U, A](r: Eff[R, A])(implicit m: Member.Aux[Safe, R, U]): Eff[U, Throwable \/ A] =
org.atnos.eff.all.execSafe(r).map(_.fold(\/.left, \/.right))
org.atnos.eff.SafeEffect.execSafe(r).map(_.fold(\/.left, \/.right))

def attemptSafeDisjunction[R, A](r: Eff[R, A])(implicit m: Safe /= R): Eff[R, (Throwable \/ A, List[Throwable])] =
org.atnos.eff.all.attemptSafe(r).map(_.leftMap(_.fold(\/.left, \/.right)))
org.atnos.eff.SafeEffect.attemptSafe(r).map(_.leftMap(_.fold(\/.left, \/.right)))

def attemptDisjunction[R, A](action: Eff[R, A])(implicit m: Safe /= R): Eff[R, Throwable \/ A] =
org.atnos.eff.all.attempt(action).map(_.fold(\/.left, \/.right))
org.atnos.eff.SafeEffect.attempt(action).map(_.fold(\/.left, \/.right))

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ object validate extends validate
trait validate {

def runValidationNel[R, U, E, A](r: Eff[R, A])(implicit m: Member.Aux[Validate[E, *], R, U]): Eff[U, ValidationNel[E, A]] =
org.atnos.eff.all.runValidatedNel(r).map(_.fold(ls => Validation.failure(NonEmptyList.fromSeq(ls.head, ls.tail)), Validation.success))
org.atnos.eff.ValidateEffect.runValidatedNel(r).map(_.fold(ls => Validation.failure(NonEmptyList.fromSeq(ls.head, ls.tail)), Validation.success))

def runNelDisjunction[R, U, E, A](r: Eff[R, A])(implicit m: Member.Aux[Validate[E, *], R, U]): Eff[U, NonEmptyList[E] \/ A] =
org.atnos.eff.all.runNel(r).map(_.fold(ls => \/.left(NonEmptyList.fromSeq(ls.head, ls.tail)), \/.right))
org.atnos.eff.ValidateEffect.runNel(r).map(_.fold(ls => \/.left(NonEmptyList.fromSeq(ls.head, ls.tail)), \/.right))

def runMapDisjunction[R, U, E, L: Semigroup, A](r: Eff[R, A])(map: E => L)(implicit m: Member.Aux[Validate[E, *], R, U]): Eff[U, L \/ A] =
org.atnos.eff.all.runMap(r)(map)(catsSemigroup(Semigroup[L]), m).map(_.fold(\/.left, \/.right))
org.atnos.eff.ValidateEffect.runMap(r)(map)(catsSemigroup(Semigroup[L]), m).map(_.fold(\/.left, \/.right))

}

0 comments on commit db8dd79

Please sign in to comment.