diff --git a/monix-tail/shared/src/main/scala/monix/tail/Iterant.scala b/monix-tail/shared/src/main/scala/monix/tail/Iterant.scala index d09d3e686..a898c5d4d 100644 --- a/monix-tail/shared/src/main/scala/monix/tail/Iterant.scala +++ b/monix-tail/shared/src/main/scala/monix/tail/Iterant.scala @@ -21,7 +21,7 @@ import java.io.PrintStream import cats.arrow.FunctionK import cats.effect.{Async, Effect, Sync, _} -import cats.{Applicative, CoflatMap, Eq, Functor, Monoid, MonoidK, Order, Parallel} +import cats.{Applicative, CoflatMap, Defer, Eq, Functor, MonadError, Monoid, MonoidK, Order, Parallel, StackSafeMonad} import scala.util.control.NonFatal import monix.execution.internal.Platform.recommendedBatchSize @@ -325,26 +325,6 @@ sealed abstract class Iterant[F[_], A] extends Product with Serializable { final def bufferSliding(count: Int, skip: Int)(implicit F: Sync[F]): Iterant[F, Seq[A]] = IterantBuffer.sliding(self, count, skip) - /** Implementation of `bracket` from `cats.effect.Bracket`. - * - * See [[https://typelevel.org/cats-effect/typeclasses/bracket.html documentation]]. - */ - final def bracket[B](use: A => Iterant[F, B])(release: A => Iterant[F, Unit]) - (implicit F: Sync[F]): Iterant[F, B] = - bracketCase(use)((a, _) => release(a)) - - /** Implementation of `bracketCase` from `cats.effect.Bracket`. - * - * See [[https://typelevel.org/cats-effect/typeclasses/bracket.html documentation]]. - */ - final def bracketCase[B](use: A => Iterant[F, B])(release: (A, ExitCase[Throwable]) => Iterant[F, Unit]) - (implicit F: Sync[F]): Iterant[F, B] = { - - self.flatMap { a => - use(a).guaranteeCase(release(a, _).completedL) - } - } - /** Builds a new iterant by applying a partial function to all * elements of the source on which the function is defined. * @@ -2100,19 +2080,6 @@ object Iterant extends IterantInstances { release) } - /** DEPRECATED — please use [[Iterant.resource]]. - * - * The `Iterant.bracket` operation was meant for streams, but - * this name in `Iterant` now refers to the semantics of the - * `cats.effect.Bracket` type class, implemented in - * [[Iterant!.bracket bracket]]. - */ - @deprecated("Use Iterant.resource", since="3.0.0-RC2") - def bracket[F[_], A, B](acquire: F[A]) - (use: A => Iterant[F, B], release: A => F[Unit]) - (implicit F: Sync[F]): Iterant[F, B] = - resource(acquire)(release).flatMap(use) - /** Lifts a strict value into the stream context, returning a * stream of one element. */ @@ -2662,39 +2629,25 @@ object Iterant extends IterantInstances { } } -private[tail] trait IterantInstances extends IterantInstances0 { - /** Provides the `cats.effect.Async` instance for [[Iterant]]. */ - implicit def catsAsyncInstances[F[_]](implicit F: Async[F]): CatsAsyncInstances[F] = - new CatsAsyncInstances[F]() - - /** Provides the `cats.effect.Async` instance for [[Iterant]]. */ - class CatsAsyncInstances[F[_]](implicit F: Async[F]) - extends CatsSyncInstances[F] - with Async[Iterant[F, ?]] { - - override def async[A](k: (Either[Throwable, A] => Unit) => Unit): Iterant[F, A] = - Iterant.liftF(F.async(k)) - override def asyncF[A](k: (Either[Throwable, A] => Unit) => Iterant[F, Unit]): Iterant[F, A] = - Iterant.liftF(F.asyncF(cb => k(cb).completedL)) - override def never[A]: Iterant[F, A] = - Iterant.never - } -} - -private[tail] trait IterantInstances0 { +private[tail] trait IterantInstances { /** Provides the `cats.effect.Sync` instance for [[Iterant]]. */ implicit def catsSyncInstances[F[_]](implicit F: Sync[F]): CatsSyncInstances[F] = new CatsSyncInstances[F]() /** Provides the `cats.effect.Sync` instance for [[Iterant]]. */ class CatsSyncInstances[F[_]](implicit F: Sync[F]) - extends Sync[Iterant[F, ?]] + extends StackSafeMonad[Iterant[F, ?]] + with MonadError[Iterant[F, ?], Throwable] + with Defer[Iterant[F, ?]] with MonoidK[Iterant[F, ?]] with CoflatMap[Iterant[F, ?]] { override def pure[A](a: A): Iterant[F, A] = Iterant.pure(a) + override def defer[A](fa: => Iterant[F, A]): Iterant[F, A] = + Iterant.suspend(fa) + override def map[A, B](fa: Iterant[F, A])(f: (A) => B): Iterant[F, B] = fa.map(f)(F) @@ -2739,17 +2692,5 @@ private[tail] trait IterantInstances0 { override def recoverWith[A](fa: Iterant[F, A])(pf: PartialFunction[Throwable, Iterant[F, A]]): Iterant[F, A] = fa.onErrorRecoverWith(pf) - - override def suspend[A](thunk: => Iterant[F, A]): Iterant[F, A] = - Iterant.suspend(thunk) - - override def delay[A](thunk: => A): Iterant[F, A] = - Iterant.eval(thunk) - - override def bracket[A, B](acquire: Iterant[F, A])(use: A => Iterant[F, B])(release: A => Iterant[F, Unit]): Iterant[F, B] = - acquire.bracket(use)(release) - - override def bracketCase[A, B](acquire: Iterant[F, A])(use: A => Iterant[F, B])(release: (A, ExitCase[Throwable]) => Iterant[F, Unit]): Iterant[F, B] = - acquire.bracketCase(use)(release) } } diff --git a/monix-tail/shared/src/test/scala/monix/tail/TypeClassLawsForIterantCoevalSuite.scala b/monix-tail/shared/src/test/scala/monix/tail/TypeClassLawsForIterantCoevalSuite.scala index 8be0a1bb2..3635a2a45 100644 --- a/monix-tail/shared/src/test/scala/monix/tail/TypeClassLawsForIterantCoevalSuite.scala +++ b/monix-tail/shared/src/test/scala/monix/tail/TypeClassLawsForIterantCoevalSuite.scala @@ -19,8 +19,7 @@ package monix.tail import cats.Eq import cats.data.EitherT -import cats.effect.laws.discipline.SyncTests -import cats.laws.discipline.{CoflatMapTests, MonadErrorTests, MonoidKTests, SemigroupalTests} +import cats.laws.discipline.{CoflatMapTests, DeferTests, MonadErrorTests, MonoidKTests, SemigroupalTests} import monix.eval.Coeval object TypeClassLawsForIterantCoevalSuite extends BaseLawsSuite { @@ -34,9 +33,8 @@ object TypeClassLawsForIterantCoevalSuite extends BaseLawsSuite { lazy val eqEitherT: Eq[EitherT[F, Throwable, Int]] = implicitly[Eq[EitherT[F, Throwable, Int]]] - checkAllAsync("Sync[Iterant[Coeval]]") { implicit ec => - implicit val eqE = eqEitherT - SyncTests[F].sync[Int, Int, Int] + checkAllAsync("Defer[Iterant[Coeval]]") { implicit ec => + DeferTests[F].defer[Int] } checkAllAsync("MonadError[Iterant[Coeval]]") { implicit ec => diff --git a/monix-tail/shared/src/test/scala/monix/tail/TypeClassLawsForIterantIOSuite.scala b/monix-tail/shared/src/test/scala/monix/tail/TypeClassLawsForIterantIOSuite.scala index e0fe6f8ed..8f0394240 100644 --- a/monix-tail/shared/src/test/scala/monix/tail/TypeClassLawsForIterantIOSuite.scala +++ b/monix-tail/shared/src/test/scala/monix/tail/TypeClassLawsForIterantIOSuite.scala @@ -21,7 +21,7 @@ import cats.Eq import cats.data.EitherT import cats.effect.IO import cats.effect.laws.discipline.AsyncTests -import cats.laws.discipline.{CoflatMapTests, MonadErrorTests, MonoidKTests, SemigroupalTests} +import cats.laws.discipline.{CoflatMapTests, DeferTests, MonadErrorTests, MonoidKTests, SemigroupalTests} import monix.execution.schedulers.TestScheduler object TypeClassLawsForIterantIOSuite extends BaseLawsSuite { @@ -37,9 +37,8 @@ object TypeClassLawsForIterantIOSuite extends BaseLawsSuite { lazy val eqEitherT: Eq[EitherT[F, Throwable, Int]] = implicitly[Eq[EitherT[F, Throwable, Int]]] - checkAllAsync("Async[Iterant[IO]]", slowConfig) { _ => - implicit val eqE = eqEitherT - AsyncTests[F].async[Int, Int, Int] + checkAllAsync("Defer[Iterant[IO]]") { implicit ec => + DeferTests[F].defer[Int] } checkAllAsync("MonadError[Iterant[IO]]") { _ => diff --git a/monix-tail/shared/src/test/scala/monix/tail/TypeClassLawsForIterantTaskSuite.scala b/monix-tail/shared/src/test/scala/monix/tail/TypeClassLawsForIterantTaskSuite.scala index d3a8df82f..86d2eb2ed 100644 --- a/monix-tail/shared/src/test/scala/monix/tail/TypeClassLawsForIterantTaskSuite.scala +++ b/monix-tail/shared/src/test/scala/monix/tail/TypeClassLawsForIterantTaskSuite.scala @@ -19,8 +19,7 @@ package monix.tail import cats.Eq import cats.data.EitherT -import cats.effect.laws.discipline.AsyncTests -import cats.laws.discipline.{CoflatMapTests, MonadErrorTests, MonoidKTests, SemigroupalTests} +import cats.laws.discipline.{CoflatMapTests, DeferTests, MonadErrorTests, MonoidKTests, SemigroupalTests} import monix.eval.Task import monix.execution.schedulers.TestScheduler @@ -37,9 +36,8 @@ object TypeClassLawsForIterantTaskSuite extends BaseLawsSuite { val eqEitherT: Eq[EitherT[F, Throwable, Int]] = implicitly[Eq[EitherT[F, Throwable, Int]]] - checkAllAsync("Async[Iterant[Task]]", slowConfig) { _ => - implicit val eqE = eqEitherT - AsyncTests[F].async[Int, Int, Int] + checkAllAsync("Defer[Iterant[Task]]", slowConfig) { _ => + DeferTests[F].defer[Int] } checkAllAsync("MonadError[Iterant[Task]]") { _ =>