Skip to content

Commit

Permalink
Close #320 - Remove Fx, FxCtor and CanCatch traits from effectie-cats…
Browse files Browse the repository at this point in the history
…-effect, effectie-cats-effect3 and effectie-monix
  • Loading branch information
kevin-lee committed Nov 27, 2021
1 parent 9cbc015 commit 46f7e63
Show file tree
Hide file tree
Showing 82 changed files with 383 additions and 513 deletions.
21 changes: 0 additions & 21 deletions cats-effect/src/main/scala-2/effectie/cats/CanCatch.scala
Original file line number Diff line number Diff line change
@@ -1,28 +1,15 @@
package effectie.cats

import cats.Id
//import cats.data.EitherT
import cats.effect.IO
import cats.syntax.all._

//import scala.concurrent.{ExecutionContext, Future}

/** @author Kevin Lee
* @since 2020-06-07
*/
//trait CanCatch[F[_]] extends effectie.CanCatch[F] {

// override type XorT[A, B] = EitherT[F, A, B]
//
// @inline override final protected def xorT[A, B](fab: F[Either[A, B]]): EitherT[F, A, B] = EitherT(fab)
//
// @inline override final protected def xorT2FEither[A, B](efab: EitherT[F, A, B]): F[Either[A, B]] = efab.value

//}

object CanCatch {
type CanCatch[F[_]] = effectie.CanCatch[F]
// def apply[F[_]: CanCatch]: CanCatch[F] = implicitly[CanCatch[F]]

implicit object CanCatchIo extends CanCatch[IO] {

Expand All @@ -33,14 +20,6 @@ object CanCatch {

}

// @SuppressWarnings(Array("org.wartremover.warts.ImplicitParameter"))
// implicit def canCatchFuture(implicit EC: ExecutionContext): CanCatch[Future] =
// new effectie.CanCatch.CanCatchFuture with CanCatch[Future] {
//
// override val EC0: ExecutionContext = EC
//
// }

implicit object CanCatchId extends CanCatch[Id] {

@inline override final def mapFa[A, B](fa: Id[A])(f: A => B): Id[B] = f(fa)
Expand Down
30 changes: 12 additions & 18 deletions cats-effect/src/main/scala-2/effectie/cats/Catching.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@ package effectie.cats

import cats.data.EitherT

import effectie.{FxCtor, CanCatch}

/** @author Kevin Lee
* @since 2020-06-07
*/
trait Catching {

import Catching._
import effectie.cats.Catching._

final def catchNonFatalThrowable[F[_]]: CurriedCanCatchThrowable[F] =
new CurriedCanCatchThrowable[F]
Expand All @@ -29,8 +27,6 @@ trait Catching {
def catchNonFatalEitherT[F[_]]: CurriedCanCatchEitherT1[F] =
new CurriedCanCatchEitherT1[F]

// def catchNonFatalEitherT[F[_], A, B](fab: => EitherT[F, A, B])(f: Throwable => A)(implicit CC: CanCatch[F]): EitherT[F, A, B] =
// CanCatch[F].catchNonFatalEitherT(fab)(f)
}

@SuppressWarnings(Array("org.wartremover.warts.DefaultArguments"))
Expand All @@ -39,8 +35,8 @@ object Catching extends Catching {
private[Catching] final class CurriedCanCatchThrowable[F[_]](
private val dummy: Boolean = true
) extends AnyVal {
def apply[B](fb: => F[B])(implicit CC: CanCatch[F]): F[Either[Throwable, B]] =
CanCatch[F].catchNonFatalThrowable[B](fb)
def apply[B](fb: => F[B])(implicit CC: effectie.CanCatch[F]): F[Either[Throwable, B]] =
effectie.CanCatch[F].catchNonFatalThrowable[B](fb)
}

private[Catching] final class CurriedCanCatch1[F[_]](
Expand All @@ -53,8 +49,8 @@ object Catching extends Catching {
private[Catching] final class CurriedCanCatch2[F[_], B](
private val fb: () => F[B]
) extends AnyVal {
def apply[A](f: Throwable => A)(implicit CC: CanCatch[F]): F[Either[A, B]] =
CanCatch[F].catchNonFatal(fb())(f)
def apply[A](f: Throwable => A)(implicit CC: effectie.CanCatch[F]): F[Either[A, B]] =
effectie.CanCatch[F].catchNonFatal(fb())(f)
}

@SuppressWarnings(Array("org.wartremover.warts.DefaultArguments"))
Expand All @@ -68,8 +64,8 @@ object Catching extends Catching {
private[Catching] final class CurriedCanCatchF2[F[_], B](
private val b: () => B
) extends AnyVal {
def apply[A](f: Throwable => A)(implicit EC: FxCtor[F], CC: CanCatch[F]): F[Either[A, B]] =
CanCatch[F].catchNonFatal(FxCtor[F].effectOf(b()))(f)
def apply[A](f: Throwable => A)(implicit EC: effectie.FxCtor[F], CC: effectie.CanCatch[F]): F[Either[A, B]] =
effectie.CanCatch[F].catchNonFatal(effectie.FxCtor[F].effectOf(b()))(f)
}

private[Catching] final class CurriedCanCatchEither1[F[_]](
Expand All @@ -82,8 +78,8 @@ object Catching extends Catching {
private[Catching] final class CurriedCanCatchEither2[F[_], A, B](
private val fab: () => F[Either[A, B]]
) extends AnyVal {
def apply(f: Throwable => A)(implicit CC: CanCatch[F]): F[Either[A, B]] =
CanCatch[F].catchNonFatalEither(fab())(f)
def apply(f: Throwable => A)(implicit CC: effectie.CanCatch[F]): F[Either[A, B]] =
effectie.CanCatch[F].catchNonFatalEither(fab())(f)
}

@SuppressWarnings(Array("org.wartremover.warts.DefaultArguments"))
Expand All @@ -97,8 +93,8 @@ object Catching extends Catching {
private[Catching] final class CurriedCanCatchEitherF2[F[_], A, B](
private val ab: () => Either[A, B]
) extends AnyVal {
def apply(f: Throwable => A)(implicit EC: FxCtor[F], CC: CanCatch[F]): F[Either[A, B]] =
CanCatch[F].catchNonFatalEither(FxCtor[F].effectOf(ab()))(f)
def apply(f: Throwable => A)(implicit EC: effectie.FxCtor[F], CC: effectie.CanCatch[F]): F[Either[A, B]] =
effectie.CanCatch[F].catchNonFatalEither(effectie.FxCtor[F].effectOf(ab()))(f)
}

private[Catching] final class CurriedCanCatchEitherT1[F[_]](
Expand All @@ -108,12 +104,10 @@ object Catching extends Catching {
new CurriedCanCatchEitherT2[F, A, B](() => fab)
}

import effectie.cats.CanCatchOps

private[Catching] final class CurriedCanCatchEitherT2[F[_], A, B](
private val fab: () => EitherT[F, A, B]
) extends AnyVal {
def apply(f: Throwable => A)(implicit CC: CanCatch[F]): EitherT[F, A, B] =
def apply(f: Throwable => A)(implicit CC: effectie.CanCatch[F]): EitherT[F, A, B] =
CC.catchNonFatalEitherT(fab())(f)
}

Expand Down
10 changes: 4 additions & 6 deletions cats-effect/src/main/scala-2/effectie/cats/ConsoleEffect.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,26 @@ import cats.syntax.all._
import effectie.ConsoleEffect.ConsoleEffectWithoutFlatMap
import effectie.YesNo

import effectie.FxCtor

trait ConsoleEffect[F[_]] extends effectie.ConsoleEffect[F]

object ConsoleEffect {
def apply[F[_]: ConsoleEffect]: ConsoleEffect[F] =
implicitly[ConsoleEffect[F]]

implicit def consoleEffectF[F[_]: FxCtor: FlatMap]: ConsoleEffect[F] =
implicit def consoleEffectF[F[_]: effectie.FxCtor: FlatMap]: ConsoleEffect[F] =
new ConsoleEffectF[F]

final class ConsoleEffectF[F[_]: FxCtor: FlatMap] extends ConsoleEffectWithoutFlatMap[F] with ConsoleEffect[F] {
final class ConsoleEffectF[F[_]: effectie.FxCtor: FlatMap] extends ConsoleEffectWithoutFlatMap[F] with ConsoleEffect[F] {

@SuppressWarnings(Array("org.wartremover.warts.Recursion"))
override def readYesNo(prompt: String): F[YesNo] = for {
_ <- putStrLn(prompt)
answer <- readLn
yesOrN <- answer match {
case "y" | "Y" =>
FxCtor[F].effectOf(YesNo.yes)
effectie.FxCtor[F].effectOf(YesNo.yes)
case "n" | "N" =>
FxCtor[F].effectOf(YesNo.no)
effectie.FxCtor[F].effectOf(YesNo.no)
case _ =>
readYesNo(prompt)
}
Expand Down
18 changes: 8 additions & 10 deletions cats-effect/src/main/scala-2/effectie/cats/Effectful.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,22 @@ package effectie.cats

import effectie.cats.Effectful._

import effectie.FxCtor


trait Effectful {

def effectOf[F[_]]: CurriedEffectOf[F] = new CurriedEffectOf[F]

def pureOf[F[_]]: CurriedEffectOfPure[F] = new CurriedEffectOfPure[F]

def unitOf[F[_]: FxCtor]: F[Unit] = FxCtor[F].unitOf
def unitOf[F[_]: effectie.FxCtor]: F[Unit] = effectie.FxCtor[F].unitOf

def errorOf[F[_]]: CurriedErrorOf[F] = new CurriedErrorOf[F]

@deprecated(message = "Use pureOf instead.", since = "1.4.0")
@inline final def effectOfPure[F[_]]: CurriedEffectOfPure[F] = pureOf[F]

@deprecated(message = "Use unitOf instead", since = "1.4.0")
@inline final def effectOfUnit[F[_]: FxCtor]: F[Unit] = unitOf[F]
@inline final def effectOfUnit[F[_]: effectie.FxCtor]: F[Unit] = unitOf[F]

}

Expand All @@ -29,22 +27,22 @@ object Effectful extends Effectful {
private[Effectful] final class CurriedEffectOf[F[_]](
private val dummy: Boolean = true
) extends AnyVal {
def apply[A](a: => A)(implicit EF: FxCtor[F]): F[A] =
FxCtor[F].effectOf(a)
def apply[A](a: => A)(implicit EF: effectie.FxCtor[F]): F[A] =
effectie.FxCtor[F].effectOf(a)
}

private[Effectful] final class CurriedEffectOfPure[F[_]](
private val dummy: Boolean = true
) extends AnyVal {
def apply[A](a: A)(implicit EF: FxCtor[F]): F[A] =
FxCtor[F].pureOf(a)
def apply[A](a: A)(implicit EF: effectie.FxCtor[F]): F[A] =
effectie.FxCtor[F].pureOf(a)
}

private[Effectful] final class CurriedErrorOf[F[_]](
private val dummy: Boolean = true
) extends AnyVal {
def apply[A](throwable: Throwable)(implicit EF: FxCtor[F]): F[A] =
FxCtor[F].errorOf(throwable)
def apply[A](throwable: Throwable)(implicit EF: effectie.FxCtor[F]): F[A] =
effectie.FxCtor[F].errorOf(throwable)
}

}
12 changes: 0 additions & 12 deletions cats-effect/src/main/scala-2/effectie/cats/Fx.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,8 @@ package effectie.cats
import cats.effect.IO
import cats.Id

//import scala.concurrent.{ExecutionContext, Future}
//import effectie.FxCtor

//trait Fx[F[_]] extends effectie.Fx[F] with FxCtor[F] with effectie.FxCtor[F] with CanCatch[F]

object Fx {
type Fx[F[_]] = effectie.Fx[F]
// def apply[F[_]: Fx]: Fx[F] = implicitly[Fx[F]]

implicit object IoFx extends Fx[IO] {

Expand All @@ -29,12 +23,6 @@ object Fx {
CanCatch.CanCatchIo.catchNonFatalThrowable(fa)
}

// @SuppressWarnings(Array("org.wartremover.warts.ImplicitParameter"))
// implicit def futureFx(implicit EC: ExecutionContext): Fx[Future] = new FutureFx

// final class FutureFx(implicit override val EC0: ExecutionContext)
// extends effectie.Fx.FxFuture

implicit object IdFx extends Fx[Id] {

@inline override final def effectOf[A](a: => A): Id[A] = a
Expand Down
10 changes: 0 additions & 10 deletions cats-effect/src/main/scala-2/effectie/cats/FxCtor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,11 @@ package effectie.cats
import cats.Id
import cats.effect.IO

//import scala.concurrent.{ExecutionContext, Future}

//import effectie.FxCtor

//trait FxCtor[F[_]] extends effectie.FxCtor[F]

object FxCtor {
type FxCtor[F[_]] = effectie.FxCtor[F]

implicit final val ioFxCtor: FxCtor[IO] = Fx.IoFx

// @SuppressWarnings(Array("org.wartremover.warts.ImplicitParameter"))
// implicit def futureFxCtor(implicit EC: ExecutionContext): FxCtor[Future] =
// effectie.FxCtor.

implicit final val idFxCtor: FxCtor[Id] = Fx.IdFx

}
32 changes: 2 additions & 30 deletions cats-effect/src/main/scala-3/effectie/cats/CanCatch.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,9 @@ import scala.concurrent.{ExecutionContext, Future}
/** @author Kevin Lee
* @since 2020-06-07
*/
trait CanCatch[F[_]] extends effectie.CanCatch[F] {

override type XorT[A, B] = EitherT[F, A, B]

inline override final protected def xorT[A, B](fab: F[Either[A, B]]): EitherT[F, A, B] = EitherT(fab)

inline override final protected def xorT2FEither[A, B](efab: EitherT[F, A, B]): F[Either[A, B]] = efab.value

}

object CanCatch {
def apply[F[_]: CanCatch]: CanCatch[F] = summon[CanCatch[F]]

type CanCatch[F[*]] = effectie.CanCatch[F]

given canCatchIo: CanCatch[IO] with {

Expand All @@ -33,25 +24,6 @@ object CanCatch {

}

given canCatchFuture(using EC: ExecutionContext): CanCatch[Future] =
new effectie.CanCatch.CanCatchFuture with CanCatch[Future] {

override val EC0: ExecutionContext = EC

override def catchNonFatalThrowable[A](fa: => Future[A]): Future[Either[Throwable, A]] =
fa.transform {
case scala.util.Success(a) =>
scala.util.Try[Either[Throwable, A]](Right(a))

case scala.util.Failure(scala.util.control.NonFatal(ex)) =>
scala.util.Try[Either[Throwable, A]](Left(ex))

case scala.util.Failure(ex) =>
throw ex
}(EC0)

}

given canCatchId: CanCatch[Id] with {

inline override final def mapFa[A, B](fa: Id[A])(f: A => B): Id[B] = f(fa)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import scala.util.control.NonFatal
/** @author Kevin Lee
* @since 2020-08-17
*/
trait CanHandleError[F[_]] extends effectie.CanHandleError[F] {
trait CanHandleError[F[*]] extends effectie.CanHandleError[F] {

type XorT[A, B] = EitherT[F, A, B]

Expand All @@ -24,7 +24,7 @@ trait CanHandleError[F[_]] extends effectie.CanHandleError[F] {

object CanHandleError {

def apply[F[_]: CanHandleError]: CanHandleError[F] = summon[CanHandleError[F]]
def apply[F[*]: CanHandleError]: CanHandleError[F] = summon[CanHandleError[F]]

given ioCanHandleError: CanHandleError[IO] with {

Expand Down
4 changes: 2 additions & 2 deletions cats-effect/src/main/scala-3/effectie/cats/CanRecover.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import scala.util.control.NonFatal
/** @author Kevin Lee
* @since 2020-08-17
*/
trait CanRecover[F[_]] extends effectie.CanRecover[F] {
trait CanRecover[F[*]] extends effectie.CanRecover[F] {

type XorT[A, B] = EitherT[F, A, B]

Expand All @@ -23,7 +23,7 @@ trait CanRecover[F[_]] extends effectie.CanRecover[F] {

object CanRecover {

def apply[F[_]: CanRecover]: CanRecover[F] = summon[CanRecover[F]]
def apply[F[*]: CanRecover]: CanRecover[F] = summon[CanRecover[F]]

given ioCanRecover: CanRecover[IO] with {
override def recoverFromNonFatalWith[A, AA >: A](fa: => IO[A])(
Expand Down

0 comments on commit 46f7e63

Please sign in to comment.