diff --git a/README.md b/README.md index b6fac47..c6c96f9 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ import avocado.* import avocado.instances.cats.given val run: IO[Int] = - ado { + parallelize { for { a <- doStuff1 b <- doStuff2(a) @@ -33,7 +33,7 @@ for { `avocADO` is a small library that allows for automatic rewriting of `for` comprehensions to their parallel versions. -The name `avocADO` is a pun on the most important function exposed by the library - `ado` (name taken from Haskell's language extension `ApplicativeDo`). +The name `avocADO` is a pun on the function that is the inspiration for this library - `ado` from Haskell's language extension `ApplicativeDo`. ## Usage (with build tools) @@ -61,9 +61,9 @@ libraryDependencies ++= Seq( ## Usage (in code) -All you need to do in order to use `avocADO` is to import the `ado` function and an `AvocADO` instance for your effect system. i.e. +All you need to do in order to use `avocADO` is to import the `parallelize` function and an `AvocADO` instance for your effect system. i.e. ```scala -import avocado.* // This line exposes the `ado` function - entrypoint of the library +import avocado.* // This line exposes the `parallelize` function - entrypoint of the library // You should choose one of the following imports depending on your effect system of choice import avocado.instances.cats.given import avocado.instances.zio2.given @@ -71,9 +71,9 @@ import avocado.instances.zio1.given import avocado.instances.zioquery.given ``` -And that's it! All that's left is to wrap the `for`-comprehensions that you want to parallelize with a call to `ado` an watch your program run in parallel! Like so: +And that's it! All that's left is to wrap the `for`-comprehensions that you want to parallelize with a call to `parallelize` an watch your program run in parallel! Like so: ```scala -ado { +parallelize { for { ... } yield ... diff --git a/avocADO/src/main/scala/ado.scala b/avocADO/src/main/scala/ado.scala index cd54533..3c5cb5e 100644 --- a/avocADO/src/main/scala/ado.scala +++ b/avocADO/src/main/scala/ado.scala @@ -2,6 +2,38 @@ package avocado import macros.* +/** + * Transforms the provided for-comprehension to it's parallel version. + * Example usage: + * ```scala + * parallelize { + * for { + * a <- doStuff1 + * b <- doStuff2(a) + * c <- doStuff3 + * d <- doStuff4(a) + * } yield combine(a, b, c, d) + * } + * ``` + * + * The above code will be transformed to code essentially equivalent to: + * ```scala + * for { + * a <- doStuff1 + * (b, c, d) <- doStuff2(a).zip(doStuff3).zip(doStuff4(a)) + * } yield combine(a, b, c, d) + * ``` + * + * The transformed code will use the provided implicit [[avocado.AvocADO]] + * instance for method calls such as `map`, `flatMap` and `zip`. Potential for + * parallelism is introduced in places where `zip` calls are used. So in order + * to utilize this method in a sensible way, [[avocado.AvocADO.zip]] should + * initialize parallel calls. Though this method should also be safe for + * sequential operations. + */ +inline def parallelize[F[_], A](inline comp: F[A])(using ap: AvocADO[F]): F[A] = + ${ macros.adoImpl[F, A]('comp, 'ap) } + /** * Transforms the provided for-comprehension to it's parallel version. * Example usage: @@ -31,6 +63,7 @@ import macros.* * initialize parallel calls. Though this method should also be safe for * sequential operations. */ +@deprecated("Use parallelize instead", "0.2.0") inline def ado[F[_], A](inline comp: F[A])(using ap: AvocADO[F]): F[A] = ${ macros.adoImpl[F, A]('comp, 'ap) } diff --git a/avocADO/src/main/scala/macros.scala b/avocADO/src/main/scala/macros.scala index 42891b0..bfddda3 100644 --- a/avocADO/src/main/scala/macros.scala +++ b/avocADO/src/main/scala/macros.scala @@ -238,7 +238,7 @@ private[avocado] object macros { } def throwGenericError(): Nothing = - report.errorAndAbort("Oopsie, wrong argument passed to ado!") + report.errorAndAbort("Oopsie, wrong argument passed to parallelize!") private def supportedRewriteMethod(name: String): Boolean = List("flatMap", "map").contains(name) diff --git a/avocADO/src/test/scala/ExplicitPipelineTests.scala b/avocADO/src/test/scala/ExplicitPipelineTests.scala index 9a77c9f..4b41e81 100644 --- a/avocADO/src/test/scala/ExplicitPipelineTests.scala +++ b/avocADO/src/test/scala/ExplicitPipelineTests.scala @@ -12,7 +12,7 @@ class ExplicitPipelineTests extends munit.FunSuite { } test("handwritten pipeline 1") { - val res = ado { + val res = parallelize { Some(1).flatMap { a => Some(2).map { b => a + b @@ -23,7 +23,7 @@ class ExplicitPipelineTests extends munit.FunSuite { } test("handwritten pipeline 2") { - val res = ado { + val res = parallelize { Some(1).flatMap { a => Some(2).flatMap { b => Some(a + b) diff --git a/avocADO/src/test/scala/OptionTests.scala b/avocADO/src/test/scala/OptionTests.scala index 9865a18..c4a1e3a 100644 --- a/avocADO/src/test/scala/OptionTests.scala +++ b/avocADO/src/test/scala/OptionTests.scala @@ -12,7 +12,7 @@ class OptionTests extends munit.FunSuite { } test("option comprehension 1") { - val res = ado { + val res = parallelize { for { a <- Some(1) b <- Some(2) @@ -22,7 +22,7 @@ class OptionTests extends munit.FunSuite { } test("option comprehension 2") { - val res = ado { + val res = parallelize { for { a <- Some(1) b <- Some(2) @@ -33,7 +33,7 @@ class OptionTests extends munit.FunSuite { } test("option comprehension 3") { - val res = ado { + val res = parallelize { for { a <- Some(1) b <- Some(2) @@ -44,7 +44,7 @@ class OptionTests extends munit.FunSuite { } test("option comprehension 4") { - val res = ado { + val res = parallelize { for { a <- Some(1) b <- Some(2) @@ -56,7 +56,7 @@ class OptionTests extends munit.FunSuite { } test("option comprehension 5") { - val res = ado { + val res = parallelize { for { a <- Some(1) b <- Some(2) @@ -69,7 +69,7 @@ class OptionTests extends munit.FunSuite { } test("option comprehension 6") { - val res = ado { + val res = parallelize { for { a <- Some(1) b <- Some(2) @@ -81,7 +81,7 @@ class OptionTests extends munit.FunSuite { } test("option comprehension 7") { - val res = ado { + val res = parallelize { for { a <- Some(1) aa <- None @@ -93,7 +93,7 @@ class OptionTests extends munit.FunSuite { } test("option comprehension 8") { - val res = ado { + val res = parallelize { for { a <- Some(1) } yield a @@ -102,7 +102,7 @@ class OptionTests extends munit.FunSuite { } test("option comprehension 9") { - val res = ado { + val res = parallelize { for { a <- Some(1) a <- Some(a) @@ -113,7 +113,7 @@ class OptionTests extends munit.FunSuite { } test("option comprehension 10") { - val res = ado { + val res = parallelize { for { a <- Some(1) b <- Some(a + 2) @@ -124,7 +124,7 @@ class OptionTests extends munit.FunSuite { } test("option comprehension 11") { - val res = ado { + val res = parallelize { for { a <- Some(1) b <- Some(a + 2) @@ -135,7 +135,7 @@ class OptionTests extends munit.FunSuite { } test("option comprehension 12") { - val res = ado { + val res = parallelize { for { _ <- Option(null) xd <- Option { @@ -147,7 +147,7 @@ class OptionTests extends munit.FunSuite { } test("option comprehension 13") { - val res = ado { + val res = parallelize { for { a <- Some(1) a <- Some(2) @@ -158,7 +158,7 @@ class OptionTests extends munit.FunSuite { test("option comprehension 14") { def getImplicit(using i: Int): Option[Int] = Some(i) - val res = ado { + val res = parallelize { for { given Int <- Some(2) b <- getImplicit @@ -169,7 +169,7 @@ class OptionTests extends munit.FunSuite { test("option comprehension 15") { def getImplicit(using i: Int): Option[Int] = Some(i) - val res = ado { + val res = parallelize { for { a <- Some(2) given Int = 1 @@ -180,7 +180,7 @@ class OptionTests extends munit.FunSuite { } test("option comprehension 16") { - val res = ado { + val res = parallelize { for { _ <- Some(2) b = 1 @@ -191,7 +191,7 @@ class OptionTests extends munit.FunSuite { test("option comprehension 17") { def getImplicit(using i: Int): Option[Int] = Some(i) - val res = ado { + val res = parallelize { for { _ <- Some(2) given Int = 1 @@ -203,7 +203,7 @@ class OptionTests extends munit.FunSuite { test("option comprehension 18") { - val res = ado { + val res = parallelize { for { a <- Some(1) (b: Int) = 2 @@ -214,7 +214,7 @@ class OptionTests extends munit.FunSuite { } test("option comprehension 19") { - val res = ado { + val res = parallelize { for { a <- Some(1) _ <- Some(2) @@ -225,7 +225,7 @@ class OptionTests extends munit.FunSuite { } test("option comprehension 20") { - val res = ado { + val res = parallelize { for { a <- Some(1) _ <- Some(2) @@ -237,7 +237,7 @@ class OptionTests extends munit.FunSuite { test("option comprehension 21") { case class C(i: Int, j: Int) - val res = ado { + val res = parallelize { for { a <- Some(1) _ <- Some(2) @@ -249,7 +249,7 @@ class OptionTests extends munit.FunSuite { test("option comprehension 22") { case class C(i: Int*) - val res = ado { + val res = parallelize { for { a <- Some(1) _ <- Some(2) diff --git a/avocADO/src/test/scalajvm/FutureTests.scala b/avocADO/src/test/scalajvm/FutureTests.scala index 35f12cb..3a0b044 100644 --- a/avocADO/src/test/scalajvm/FutureTests.scala +++ b/avocADO/src/test/scalajvm/FutureTests.scala @@ -21,7 +21,7 @@ class FutureTests extends munit.FunSuite { testWithTimeLimit("Future comprehension 1", 900) { def wait = Future(Thread.sleep(500)) - ado { + parallelize { for { a <- Future(1) } yield a @@ -30,7 +30,7 @@ class FutureTests extends munit.FunSuite { testWithTimeLimit("Future comprehension 2", 900) { def wait = Future(Thread.sleep(500)) - ado { + parallelize { for { a <- wait.map(_ => 1) b <- wait.map(_ => 2) @@ -40,7 +40,7 @@ class FutureTests extends munit.FunSuite { testWithTimeLimit("Future comprehension 3", 1400) { def wait = Future(Thread.sleep(500)) - ado { + parallelize { for { a <- wait.map(_ => 1) b <- wait.map(_ => 2) diff --git a/cats/src/test/scalajvm/CatsEffect3TCTests.scala b/cats/src/test/scalajvm/CatsEffect3TCTests.scala index b66ad71..75b2031 100644 --- a/cats/src/test/scalajvm/CatsEffect3TCTests.scala +++ b/cats/src/test/scalajvm/CatsEffect3TCTests.scala @@ -13,7 +13,7 @@ class CatsEffect3TCTests extends BaseCatsEffect3Test { testWithTimeLimit("cats effect 3 comprehension with typeclasses 1", 900) { val wait = IO.sleep(500.millis) - def run[F[_]: Monad: AvocADO](wait: F[Unit]): F[Int] = ado { + def run[F[_]: Monad: AvocADO](wait: F[Unit]): F[Int] = parallelize { for { a <- Monad[F].pure(1) } yield a @@ -23,7 +23,7 @@ class CatsEffect3TCTests extends BaseCatsEffect3Test { testWithTimeLimit("cats effect 3 comprehension with typeclasses 2", 900) { val wait = IO.sleep(500.millis) - def run[F[_]: Monad: AvocADO](wait: F[Unit]): F[Int] = ado { + def run[F[_]: Monad: AvocADO](wait: F[Unit]): F[Int] = parallelize { for { a <- wait.map(_ => 1) b <- wait.map(_ => 2) @@ -34,7 +34,7 @@ class CatsEffect3TCTests extends BaseCatsEffect3Test { testWithTimeLimit("cats effect 3 comprehension with typeclasses 3", 1400) { val wait = IO.sleep(500.millis) - def run[F[_]: Monad: AvocADO](wait: F[Unit]): F[Int] = ado { + def run[F[_]: Monad: AvocADO](wait: F[Unit]): F[Int] = parallelize { for { a <- wait.map(_ => 1) b <- wait.map(_ => 2) @@ -47,7 +47,7 @@ class CatsEffect3TCTests extends BaseCatsEffect3Test { testWithTimeLimit("cats effect 3 comprehension with typeclasses 4", 1400) { val wait = IO.sleep(500.millis) - def run[F[_]: Monad: AvocADO](wait: F[Unit]): F[Int] = ado { + def run[F[_]: Monad: AvocADO](wait: F[Unit]): F[Int] = parallelize { for { a <- wait.map(_ => 1) b <- wait.map(_ => 2) @@ -61,7 +61,7 @@ class CatsEffect3TCTests extends BaseCatsEffect3Test { testWithTimeLimit("cats effect 3 comprehension with typeclasses 5", 1400) { val wait = IO.sleep(500.millis) - def run[F[_]: Monad: AvocADO](wait: F[Unit]): F[Int] = ado { + def run[F[_]: Monad: AvocADO](wait: F[Unit]): F[Int] = parallelize { for { a <- wait.map(_ => 1) b <- wait.map(_ => 2) @@ -75,7 +75,7 @@ class CatsEffect3TCTests extends BaseCatsEffect3Test { testWithTimeLimit("cats effect 3 comprehension with typeclasses 6", 1400) { val wait = IO.sleep(500.millis) - def run[F[_]: Monad: AvocADO](wait: F[Unit]): F[Int] = ado { + def run[F[_]: Monad: AvocADO](wait: F[Unit]): F[Int] = parallelize { for { a <- wait.map(_ => 1) b <- wait.map(_ => 2) @@ -91,7 +91,7 @@ class CatsEffect3TCTests extends BaseCatsEffect3Test { testWithTimeLimit("cats effect 3 comprehension with typeclasses 7", 900) { val wait = IO.sleep(500.millis) - def run[F[_]: Monad: AvocADO](wait: F[Unit]): F[Int] = ado { + def run[F[_]: Monad: AvocADO](wait: F[Unit]): F[Int] = parallelize { for { a <- wait.map(_ => 1) b <- wait.map(_ => 2) @@ -103,7 +103,7 @@ class CatsEffect3TCTests extends BaseCatsEffect3Test { testWithTimeLimit("cats effect 3 comprehension with typeclasses 8", 900) { val wait = IO.sleep(500.millis) - def run[F[_]: Monad: AvocADO](wait: F[Unit]): F[Int] = ado { + def run[F[_]: Monad: AvocADO](wait: F[Unit]): F[Int] = parallelize { for { a <- wait.map(_ => 1) b <- wait.map(_ => 2) @@ -116,7 +116,7 @@ class CatsEffect3TCTests extends BaseCatsEffect3Test { testWithTimeLimit("cats effect 3 comprehension with typeclasses 9", 900) { val wait = IO.sleep(500.millis) - def run[F[_]: Monad: AvocADO](wait: F[Unit]): F[Int] = ado { + def run[F[_]: Monad: AvocADO](wait: F[Unit]): F[Int] = parallelize { for { _ <- wait a <- wait.map(_ => 1) @@ -130,7 +130,7 @@ class CatsEffect3TCTests extends BaseCatsEffect3Test { testWithTimeLimit("cats effect 3 comprehension with typeclasses 10", 1400) { val wait = IO.sleep(500.millis) - def run[F[_]: Monad: AvocADO](wait: F[Unit]): F[Int] = ado { + def run[F[_]: Monad: AvocADO](wait: F[Unit]): F[Int] = parallelize { for { a <- wait.map(_ => 1) _ <- wait.map(_ => a) @@ -143,7 +143,7 @@ class CatsEffect3TCTests extends BaseCatsEffect3Test { testWithTimeLimit("cats effect 3 comprehension with typeclasses 11", 900) { val wait = IO.sleep(500.millis) - def run[F[_]: Monad: AvocADO](wait: F[Unit]): F[Int] = ado { + def run[F[_]: Monad: AvocADO](wait: F[Unit]): F[Int] = parallelize { for { a <- wait.map(_ => 1) b <- wait.map(_ => { @@ -157,7 +157,7 @@ class CatsEffect3TCTests extends BaseCatsEffect3Test { testWithTimeLimit("cats effect 3 comprehension with typeclasses 12", 900) { val wait = IO.sleep(500.millis) - def run[F[_]: Monad: AvocADO](wait: F[Unit]): F[Int] = ado { + def run[F[_]: Monad: AvocADO](wait: F[Unit]): F[Int] = parallelize { for { a <- wait.map(_ => 1) b <- wait.map(_ => { @@ -175,7 +175,7 @@ class CatsEffect3TCTests extends BaseCatsEffect3Test { testWithTimeLimit("cats effect 3 comprehension with typeclasses 13", 900) { val wait = IO.sleep(500.millis) - def run[F[_]: Monad: AvocADO](wait: F[Unit]): F[Int] = ado { + def run[F[_]: Monad: AvocADO](wait: F[Unit]): F[Int] = parallelize { for { a <- wait.map(_ => 1) b = 2 @@ -187,7 +187,7 @@ class CatsEffect3TCTests extends BaseCatsEffect3Test { testWithTimeLimit("cats effect 3 comprehension with typeclasses 14", 900) { val wait = IO.sleep(500.millis) - def run[F[_]: Monad: AvocADO](wait: F[Unit]): F[Int] = ado { + def run[F[_]: Monad: AvocADO](wait: F[Unit]): F[Int] = parallelize { for { a <- wait.map(_ => 1) b = 2 @@ -200,7 +200,7 @@ class CatsEffect3TCTests extends BaseCatsEffect3Test { testWithTimeLimit("cats effect 3 comprehension with typeclasses 15", 1400) { val wait = IO.sleep(500.millis) - def run[F[_]: Monad: AvocADO](wait: F[Unit]): F[Int] = ado { + def run[F[_]: Monad: AvocADO](wait: F[Unit]): F[Int] = parallelize { for { a <- wait.map(_ => 1) b = 2 @@ -213,7 +213,7 @@ class CatsEffect3TCTests extends BaseCatsEffect3Test { testWithTimeLimit("cats effect 3 comprehension with typeclasses 16", 1400) { val wait = IO.sleep(500.millis) - def run[F[_]: Monad: AvocADO](wait: F[Unit]): F[Int] = ado { + def run[F[_]: Monad: AvocADO](wait: F[Unit]): F[Int] = parallelize { for { a <- wait.map(_ => 1) b = 2 @@ -226,7 +226,7 @@ class CatsEffect3TCTests extends BaseCatsEffect3Test { testWithTimeLimit("cats effect 3 comprehension with typeclasses 17", 1400) { val wait = IO.sleep(500.millis) - def run[F[_]: Monad: AvocADO](wait: F[Unit]): F[Int] = ado { + def run[F[_]: Monad: AvocADO](wait: F[Unit]): F[Int] = parallelize { for { a <- wait.map(_ => 1) b <- wait.map(_ => 2) @@ -240,7 +240,7 @@ class CatsEffect3TCTests extends BaseCatsEffect3Test { testWithTimeLimit("cats effect 3 comprehension with typeclasses 18", 1400) { val wait = IO.sleep(500.millis) - def run[F[_]: Monad: AvocADO](wait: F[Unit]): F[Int] = ado { + def run[F[_]: Monad: AvocADO](wait: F[Unit]): F[Int] = parallelize { for { a <- wait.map(_ => 1) b <- wait.map(_ => 2) @@ -254,7 +254,7 @@ class CatsEffect3TCTests extends BaseCatsEffect3Test { testWithTimeLimit("cats effect 3 comprehension with typeclasses 19", 1400) { val wait = IO.sleep(500.millis) - def run[F[_]: Monad: AvocADO](wait: F[Unit]): F[Int] = ado { + def run[F[_]: Monad: AvocADO](wait: F[Unit]): F[Int] = parallelize { for { a <- wait.map(_ => 1) b = 2 diff --git a/cats/src/test/scalajvm/CatsEffect3Tests.scala b/cats/src/test/scalajvm/CatsEffect3Tests.scala index da60296..3914b47 100644 --- a/cats/src/test/scalajvm/CatsEffect3Tests.scala +++ b/cats/src/test/scalajvm/CatsEffect3Tests.scala @@ -11,7 +11,7 @@ class CatsEffect3Tests extends BaseCatsEffect3Test { testWithTimeLimit("cats effect 3 comprehension 1", 900) { val wait = IO.sleep(500.millis) - ado { + parallelize { for { a <- IO(1) } yield a @@ -20,7 +20,7 @@ class CatsEffect3Tests extends BaseCatsEffect3Test { testWithTimeLimit("cats effect 3 comprehension 2", 900) { val wait = IO.sleep(500.millis) - ado { + parallelize { for { a <- wait.map(_ => 1) b <- wait.map(_ => 2) @@ -30,7 +30,7 @@ class CatsEffect3Tests extends BaseCatsEffect3Test { testWithTimeLimit("cats effect 3 comprehension 3", 1400) { val wait = IO.sleep(500.millis) - ado { + parallelize { for { a <- wait.map(_ => 1) b <- wait.map(_ => 2) @@ -42,7 +42,7 @@ class CatsEffect3Tests extends BaseCatsEffect3Test { testWithTimeLimit("cats effect 3 comprehension 4", 1400) { val wait = IO.sleep(500.millis) - ado { + parallelize { for { a <- wait.map(_ => 1) b <- wait.map(_ => 2) @@ -55,7 +55,7 @@ class CatsEffect3Tests extends BaseCatsEffect3Test { testWithTimeLimit("cats effect 3 comprehension 5", 1400) { val wait = IO.sleep(500.millis) - ado { + parallelize { for { a <- wait.map(_ => 1) b <- wait.map(_ => 2) @@ -68,7 +68,7 @@ class CatsEffect3Tests extends BaseCatsEffect3Test { testWithTimeLimit("cats effect 3 comprehension 6", 1400) { val wait = IO.sleep(500.millis) - ado { + parallelize { for { a <- wait.map(_ => 1) b <- wait.map(_ => 2) @@ -83,7 +83,7 @@ class CatsEffect3Tests extends BaseCatsEffect3Test { testWithTimeLimit("cats effect 3 comprehension 7", 900) { val wait = IO.sleep(500.millis) - ado { + parallelize { for { a <- wait.map(_ => 1) b <- wait.map(_ => 2) @@ -94,7 +94,7 @@ class CatsEffect3Tests extends BaseCatsEffect3Test { testWithTimeLimit("cats effect 3 comprehension 8", 900) { val wait = IO.sleep(500.millis) - ado { + parallelize { for { a <- wait.map(_ => 1) b <- wait.map(_ => 2) @@ -106,7 +106,7 @@ class CatsEffect3Tests extends BaseCatsEffect3Test { testWithTimeLimit("cats effect 3 comprehension 9", 900) { val wait = IO.sleep(500.millis) - ado { + parallelize { for { _ <- wait a <- wait.map(_ => 1) @@ -119,7 +119,7 @@ class CatsEffect3Tests extends BaseCatsEffect3Test { testWithTimeLimit("cats effect 3 comprehension 10", 1400) { val wait = IO.sleep(500.millis) - ado { + parallelize { for { a <- wait.map(_ => 1) _ <- wait.map(_ => a) @@ -131,7 +131,7 @@ class CatsEffect3Tests extends BaseCatsEffect3Test { testWithTimeLimit("cats effect 3 comprehension 11", 900) { val wait = IO.sleep(500.millis) - ado { + parallelize { for { a <- wait.map(_ => 1) b <- wait.map(_ => { @@ -144,7 +144,7 @@ class CatsEffect3Tests extends BaseCatsEffect3Test { testWithTimeLimit("cats effect 3 comprehension 12", 900) { val wait = IO.sleep(500.millis) - ado { + parallelize { for { a <- wait.map(_ => 1) b <- wait.map(_ => { @@ -161,7 +161,7 @@ class CatsEffect3Tests extends BaseCatsEffect3Test { testWithTimeLimit("cats effect 3 comprehension 13", 900) { val wait = IO.sleep(500.millis) - ado { + parallelize { for { a <- wait.map(_ => 1) b = 2 @@ -172,7 +172,7 @@ class CatsEffect3Tests extends BaseCatsEffect3Test { testWithTimeLimit("cats effect 3 comprehension 14", 900) { val wait = IO.sleep(500.millis) - ado { + parallelize { for { a <- wait.map(_ => 1) b = 2 @@ -184,7 +184,7 @@ class CatsEffect3Tests extends BaseCatsEffect3Test { testWithTimeLimit("cats effect 3 comprehension 15", 1400) { val wait = IO.sleep(500.millis) - ado { + parallelize { for { a <- wait.map(_ => 1) b = 2 @@ -196,7 +196,7 @@ class CatsEffect3Tests extends BaseCatsEffect3Test { testWithTimeLimit("cats effect 3 comprehension 16", 1400) { val wait = IO.sleep(500.millis) - ado { + parallelize { for { a <- wait.map(_ => 1) b = 2 @@ -208,7 +208,7 @@ class CatsEffect3Tests extends BaseCatsEffect3Test { testWithTimeLimit("cats effect 3 comprehension 17", 1400) { val wait = IO.sleep(500.millis) - ado { + parallelize { for { a <- wait.map(_ => 1) b <- wait.map(_ => 2) @@ -221,7 +221,7 @@ class CatsEffect3Tests extends BaseCatsEffect3Test { testWithTimeLimit("cats effect 3 comprehension 18", 1400) { val wait = IO.sleep(500.millis) - ado { + parallelize { for { a <- wait.map(_ => 1) b <- wait.map(_ => 2) @@ -234,7 +234,7 @@ class CatsEffect3Tests extends BaseCatsEffect3Test { testWithTimeLimit("cats effect 3 comprehension 19", 1400) { val wait = IO.sleep(500.millis) - ado { + parallelize { for { a <- wait.map(_ => 1) b = 2 @@ -249,7 +249,7 @@ class CatsEffect3Tests extends BaseCatsEffect3Test { testWithTimeLimit("cats effect 3 comprehension 20", 1400) { val wait = IO.sleep(500.millis) - ado { + parallelize { for { a <- wait.map(_ => 1) b <- wait.map(_ => a + 1) @@ -262,7 +262,7 @@ class CatsEffect3Tests extends BaseCatsEffect3Test { testWithTimeLimit("cats effect 3 comprehension 21", 1400) { val wait = IO.sleep(500.millis) def getImplicit(using i: Int): IO[Int] = wait.map(_ => i) - ado { + parallelize { for { a <- wait.map(_ => 1) given Int <- wait.map(_ => 2) @@ -274,7 +274,7 @@ class CatsEffect3Tests extends BaseCatsEffect3Test { testWithTimeLimit("cats effect 3 comprehension 22", 1900) { val wait = IO.sleep(500.millis) def getImplicit(using i: Int): IO[Int] = wait.map(_ => i) - ado { + parallelize { for { a <- wait.map(_ => 1) b <- wait.map(_ => 2) @@ -288,7 +288,7 @@ class CatsEffect3Tests extends BaseCatsEffect3Test { testWithTimeLimit("cats effect 3 comprehension 23", 900) { val wait = IO.sleep(500.millis) - ado { + parallelize { for { _ <- wait.map(_ => 2) b = 1 @@ -299,7 +299,7 @@ class CatsEffect3Tests extends BaseCatsEffect3Test { testWithTimeLimit("cats effect 3 comprehension 24", 1400) { val wait = IO.sleep(500.millis) def getImplicit(using i: Int): IO[Int] = wait.map(_ => i) - ado { + parallelize { for { _ <- wait.map(_ => 2) given Int = 1 @@ -310,7 +310,7 @@ class CatsEffect3Tests extends BaseCatsEffect3Test { testWithTimeLimit("cats effect 3 comprehension 25", 1400) { val wait = IO.sleep(500.millis) - ado { + parallelize { for { a <- wait.map(_ => 1) (b: Int) = 2 @@ -321,7 +321,7 @@ class CatsEffect3Tests extends BaseCatsEffect3Test { testWithTimeLimit("cats effect 3 comprehension 26", 1400) { val wait = IO.sleep(500.millis) - ado { + parallelize { for { a <- wait.map(_ => 1) (b: Int) = a @@ -332,7 +332,7 @@ class CatsEffect3Tests extends BaseCatsEffect3Test { testWithTimeLimit("cats effect 3 comprehension 27", 1400) { val wait = IO.sleep(500.millis) - ado { + parallelize { for { a <- wait.map(_ => 1) b <- wait.map(_ => 2) @@ -345,7 +345,7 @@ class CatsEffect3Tests extends BaseCatsEffect3Test { testWithTimeLimit("cats effect 3 comprehension 28", 1400) { val wait = IO.sleep(500.millis) - ado { + parallelize { for { a <- wait.map(_ => 1) b <- wait.map(_ => 2) @@ -358,7 +358,7 @@ class CatsEffect3Tests extends BaseCatsEffect3Test { testWithTimeLimit("cats effect 3 comprehension 29", 1400) { val wait = IO.sleep(500.millis) - ado { + parallelize { for { a <- wait.map(_ => 1) b <- wait.map(_ => 2) @@ -372,7 +372,7 @@ class CatsEffect3Tests extends BaseCatsEffect3Test { testWithTimeLimit("cats effect 3 comprehension 30", 1400) { val wait = IO.sleep(500.millis) case class C(i: Int) - ado { + parallelize { for { a <- wait.map(_ => 1) b <- wait.map(_ => 2) @@ -386,7 +386,7 @@ class CatsEffect3Tests extends BaseCatsEffect3Test { testWithTimeLimit("cats effect 3 comprehension 31", 1400) { val wait = IO.sleep(500.millis) case class C(i: Int) - ado { + parallelize { for { a <- wait.map(_ => 1) b <- wait.map(_ => 2) @@ -402,7 +402,7 @@ class CatsEffect3Tests extends BaseCatsEffect3Test { object obj { case class AClass[T](t: T) } - ado { + parallelize { for { a <- wait.map(_ => 1) b <- wait.map(_ => 2) @@ -418,7 +418,7 @@ class CatsEffect3Tests extends BaseCatsEffect3Test { object obj { case class AClass[T](t: T) } - ado { + parallelize { for { a <- wait.map(_ => 1) b <- wait.map(_ => 2) @@ -434,7 +434,7 @@ class CatsEffect3Tests extends BaseCatsEffect3Test { object obj { case class AClass[T](t: T) } - ado { + parallelize { for { a <- wait.map(_ => 1) b <- wait.map(_ => 2) @@ -448,7 +448,7 @@ class CatsEffect3Tests extends BaseCatsEffect3Test { testWithTimeLimit("cats effect 3 comprehension 35", 1400) { val wait = IO.sleep(500.millis) case class C(i: Int) - ado { + parallelize { for { a <- wait.map(_ => 1) b <- wait.map(_ => 2) @@ -462,7 +462,7 @@ class CatsEffect3Tests extends BaseCatsEffect3Test { testWithTimeLimit("cats effect 3 comprehension 36", 1400) { val wait = IO.sleep(500.millis) case class C(i: Int) - ado { + parallelize { for { a <- wait.map(_ => 1) b <- wait.map(_ => 2) @@ -476,7 +476,7 @@ class CatsEffect3Tests extends BaseCatsEffect3Test { testWithTimeLimit("cats effect 3 comprehension 37", 1900) { val wait = IO.sleep(500.millis) case class C(i: Int) - ado { + parallelize { for { a <- wait.map(_ => 1) b <- wait.map(_ => 2) @@ -491,7 +491,7 @@ class CatsEffect3Tests extends BaseCatsEffect3Test { testWithTimeLimit("cats effect 3 comprehension 38", 1900) { val wait = IO.sleep(500.millis) case class C(i: Int*) - ado { + parallelize { for { a <- wait.map(_ => 1) b <- wait.map(_ => 2) @@ -506,7 +506,7 @@ class CatsEffect3Tests extends BaseCatsEffect3Test { testWithTimeLimit("cats effect 3 comprehension 39", 1900) { val wait = IO.sleep(500.millis) case class C(i: Int) - ado { + parallelize { for { a <- wait.map(_ => 1) b <- wait.map(_ => 2) @@ -521,7 +521,7 @@ class CatsEffect3Tests extends BaseCatsEffect3Test { testWithTimeLimit("cats effect 3 comprehension 40", 1900) { val wait = IO.sleep(500.millis) case class C(i: Int*) - ado { + parallelize { for { a <- wait.map(_ => 1) b <- wait.map(_ => 2) diff --git a/docs/_docs/index.md b/docs/_docs/index.md index d86e75e..6346b35 100644 --- a/docs/_docs/index.md +++ b/docs/_docs/index.md @@ -9,7 +9,7 @@ import avocado.* import avocado.instances.cats.given val run: IO[Int] = - ado { + parallelize { for { a <- doStuff1 b <- doStuff2(a) @@ -31,7 +31,7 @@ for { `avocADO` is a small library that allows for automatic rewriting of `for` comprehensions to their parallel versions. -The name `avocADO` is a pun on the most important function exposed by the library - `ado` (name taken from Haskell's language extension `ApplicativeDo`). +The name `avocADO` is a pun on the function that is the inspiration for this library - `ado` from Haskell's language extension `ApplicativeDo`. ## Usage (with build tools) @@ -59,9 +59,9 @@ libraryDependencies ++= Seq( ## Usage (in code) -All you need to do in order to use `avocADO` is to import the `ado` function and an `AvocADO` instance for your effect system. i.e. +All you need to do in order to use `avocADO` is to import the `parallelize` function and an `AvocADO` instance for your effect system. i.e. ```scala -import avocado.* // This line exposes the `ado` function - entrypoint of the library +import avocado.* // This line exposes the `parallelize` function - entrypoint of the library // You should choose one of the following imports depending on your effect system of choice import avocado.instances.cats.given import avocado.instances.zio2.given @@ -69,9 +69,9 @@ import avocado.instances.zio1.given import avocado.instances.zioquery.given ``` -And that's it! All that's left is to wrap the `for`-comprehensions that you want to parallelize with a call to `ado` an watch your program run in parallel! Like so: +And that's it! All that's left is to wrap the `for`-comprehensions that you want to parallelize with a call to `parallelize` an watch your program run in parallel! Like so: ```scala -ado { +parallelize { for { ... } yield ... diff --git a/zio-1/src/test/scalajvm/ZIO1Tests.scala b/zio-1/src/test/scalajvm/ZIO1Tests.scala index efc5526..8a9d3de 100644 --- a/zio-1/src/test/scalajvm/ZIO1Tests.scala +++ b/zio-1/src/test/scalajvm/ZIO1Tests.scala @@ -10,7 +10,7 @@ class ZIO1Tests extends BaseZIO1Test { testWithTimeLimit("ZIO1 comprehension 1", 4000) { val wait = ZIO.sleep(1000.millis) - ado { + parallelize { for { a <- wait.map(_ => 1) } yield a @@ -19,7 +19,7 @@ class ZIO1Tests extends BaseZIO1Test { testWithTimeLimit("ZIO1 comprehension 2", 900) { val wait = ZIO.sleep(500.millis) - ado { + parallelize { for { a <- wait.map(_ => 1) b <- wait.map(_ => 2) @@ -29,7 +29,7 @@ class ZIO1Tests extends BaseZIO1Test { testWithTimeLimit("ZIO1 comprehension 3", 1400) { val wait = ZIO.sleep(500.millis) - ado { + parallelize { for { a <- wait.map(_ => 1) b <- wait.map(_ => 2) @@ -41,7 +41,7 @@ class ZIO1Tests extends BaseZIO1Test { testWithTimeLimit("ZIO1 comprehension 4", 1400) { val wait = ZIO.sleep(500.millis) - ado { + parallelize { for { a <- wait.map(_ => 1) b <- wait.map(_ => 2) @@ -54,7 +54,7 @@ class ZIO1Tests extends BaseZIO1Test { testWithTimeLimit("ZIO1 comprehension 5", 1400) { val wait = ZIO.sleep(500.millis) - ado { + parallelize { for { a <- wait.map(_ => 1) b <- wait.map(_ => 2) @@ -67,7 +67,7 @@ class ZIO1Tests extends BaseZIO1Test { testWithTimeLimit("ZIO1 comprehension 6", 1400) { val wait = ZIO.sleep(500.millis) - ado { + parallelize { for { a <- wait.map(_ => 1) b <- wait.map(_ => 2) @@ -82,7 +82,7 @@ class ZIO1Tests extends BaseZIO1Test { testWithTimeLimit("ZIO1 comprehension 7", 900) { val wait = ZIO.sleep(500.millis) - ado { + parallelize { for { a <- wait.map(_ => 1) b <- wait.map(_ => 2) @@ -93,7 +93,7 @@ class ZIO1Tests extends BaseZIO1Test { testWithTimeLimit("ZIO1 comprehension 8", 900) { val wait = ZIO.sleep(500.millis) - ado { + parallelize { for { a <- wait.map(_ => 1) b <- wait.map(_ => 2) @@ -105,7 +105,7 @@ class ZIO1Tests extends BaseZIO1Test { testWithTimeLimit("ZIO1 comprehension 9", 900) { val wait = ZIO.sleep(500.millis) - ado { + parallelize { for { _ <- wait a <- wait.map(_ => 1) @@ -118,7 +118,7 @@ class ZIO1Tests extends BaseZIO1Test { testWithTimeLimit("ZIO1 comprehension 10", 1400) { val wait = ZIO.sleep(500.millis) - ado { + parallelize { for { a <- wait.map(_ => 1) _ <- wait.map(_ => a) @@ -130,7 +130,7 @@ class ZIO1Tests extends BaseZIO1Test { testWithTimeLimit("ZIO1 comprehension 11", 900) { val wait = ZIO.sleep(500.millis) - ado { + parallelize { for { a <- wait.map(_ => 1) b <- wait.map(_ => { @@ -143,7 +143,7 @@ class ZIO1Tests extends BaseZIO1Test { testWithTimeLimit("ZIO1 comprehension 12", 900) { val wait = ZIO.sleep(500.millis) - ado { + parallelize { for { a <- wait.map(_ => 1) b <- wait.map(_ => { @@ -160,7 +160,7 @@ class ZIO1Tests extends BaseZIO1Test { testWithTimeLimit("ZIO1 comprehension 13", 900) { val wait = ZIO.sleep(500.millis) - ado { + parallelize { for { a <- wait.map(_ => 1) b <- wait.map(_ => 2) @@ -171,7 +171,7 @@ class ZIO1Tests extends BaseZIO1Test { testWithTimeLimit("ZIO1 comprehension 14", 900) { val wait = ZIO.sleep(500.millis) - ado { + parallelize { for { a <- wait.map(_ => 1) b <- wait.map(_ => 2) diff --git a/zio-2/src/test/scalajvm/ZIO2Tests.scala b/zio-2/src/test/scalajvm/ZIO2Tests.scala index 29c8216..b0fee2f 100644 --- a/zio-2/src/test/scalajvm/ZIO2Tests.scala +++ b/zio-2/src/test/scalajvm/ZIO2Tests.scala @@ -9,7 +9,7 @@ class ZIO2Tests extends BaseZIO2Test { testWithTimeLimit("ZIO2 comprehension 1", 4000) { val wait = ZIO.sleep(1000.millis) - ado { + parallelize { for { a <- wait.map(_ => 1) } yield a @@ -18,7 +18,7 @@ class ZIO2Tests extends BaseZIO2Test { testWithTimeLimit("ZIO2 comprehension 2", 900) { val wait = ZIO.sleep(500.millis) - ado { + parallelize { for { a <- wait.map(_ => 1) b <- wait.map(_ => 2) @@ -28,7 +28,7 @@ class ZIO2Tests extends BaseZIO2Test { testWithTimeLimit("ZIO2 comprehension 3", 1400) { val wait = ZIO.sleep(500.millis) - ado { + parallelize { for { a <- wait.map(_ => 1) b <- wait.map(_ => 2) @@ -40,7 +40,7 @@ class ZIO2Tests extends BaseZIO2Test { testWithTimeLimit("ZIO2 comprehension 4", 1400) { val wait = ZIO.sleep(500.millis) - ado { + parallelize { for { a <- wait.map(_ => 1) b <- wait.map(_ => 2) @@ -53,7 +53,7 @@ class ZIO2Tests extends BaseZIO2Test { testWithTimeLimit("ZIO2 comprehension 5", 1400) { val wait = ZIO.sleep(500.millis) - ado { + parallelize { for { a <- wait.map(_ => 1) b <- wait.map(_ => 2) @@ -66,7 +66,7 @@ class ZIO2Tests extends BaseZIO2Test { testWithTimeLimit("ZIO2 comprehension 6", 1400) { val wait = ZIO.sleep(500.millis) - ado { + parallelize { for { a <- wait.map(_ => 1) b <- wait.map(_ => 2) @@ -81,7 +81,7 @@ class ZIO2Tests extends BaseZIO2Test { testWithTimeLimit("ZIO2 comprehension 7", 900) { val wait = ZIO.sleep(500.millis) - ado { + parallelize { for { a <- wait.map(_ => 1) b <- wait.map(_ => 2) @@ -92,7 +92,7 @@ class ZIO2Tests extends BaseZIO2Test { testWithTimeLimit("ZIO2 comprehension 8", 900) { val wait = ZIO.sleep(500.millis) - ado { + parallelize { for { a <- wait.map(_ => 1) b <- wait.map(_ => 2) @@ -104,7 +104,7 @@ class ZIO2Tests extends BaseZIO2Test { testWithTimeLimit("ZIO2 comprehension 9", 900) { val wait = ZIO.sleep(500.millis) - ado { + parallelize { for { _ <- wait a <- wait.map(_ => 1) @@ -117,7 +117,7 @@ class ZIO2Tests extends BaseZIO2Test { testWithTimeLimit("ZIO2 comprehension 10", 1400) { val wait = ZIO.sleep(500.millis) - ado { + parallelize { for { a <- wait.map(_ => 1) _ <- wait.map(_ => a) @@ -129,7 +129,7 @@ class ZIO2Tests extends BaseZIO2Test { testWithTimeLimit("ZIO2 comprehension 11", 900) { val wait = ZIO.sleep(500.millis) - ado { + parallelize { for { a <- wait.map(_ => 1) b <- wait.map(_ => { @@ -142,7 +142,7 @@ class ZIO2Tests extends BaseZIO2Test { testWithTimeLimit("ZIO2 comprehension 12", 900) { val wait = ZIO.sleep(500.millis) - ado { + parallelize { for { a <- wait.map(_ => 1) b <- wait.map(_ => { @@ -159,7 +159,7 @@ class ZIO2Tests extends BaseZIO2Test { testWithTimeLimit("ZIO2 comprehension 13", 900) { val wait = ZIO.sleep(500.millis) - ado { + parallelize { for { a <- wait.map(_ => 1) b <- wait.map(_ => 2) @@ -170,7 +170,7 @@ class ZIO2Tests extends BaseZIO2Test { testWithTimeLimit("ZIO2 comprehension 14", 900) { val wait = ZIO.sleep(500.millis) - ado { + parallelize { for { a <- wait.map(_ => 1) b <- wait.map(_ => 2) diff --git a/zio-query/src/test/scalajvm/ZQueryTests.scala b/zio-query/src/test/scalajvm/ZQueryTests.scala index 67ac924..c14b0bb 100644 --- a/zio-query/src/test/scalajvm/ZQueryTests.scala +++ b/zio-query/src/test/scalajvm/ZQueryTests.scala @@ -10,7 +10,7 @@ class ZQueryTests extends BaseZQueryTest { testWithTimeLimit("ZQuery comprehension 1", 4000) { val wait = ZQuery.fromZIO(ZIO.sleep(1000.millis)) - ado { + parallelize { for { a <- wait.map(_ => 1) } yield a @@ -19,7 +19,7 @@ class ZQueryTests extends BaseZQueryTest { testWithTimeLimit("ZQuery comprehension 2", 900) { val wait = ZQuery.fromZIO(ZIO.sleep(500.millis)) - ado { + parallelize { for { a <- wait.map(_ => 1) b <- wait.map(_ => 2) @@ -29,7 +29,7 @@ class ZQueryTests extends BaseZQueryTest { testWithTimeLimit("ZQuery comprehension 3", 1400) { val wait = ZQuery.fromZIO(ZIO.sleep(500.millis)) - ado { + parallelize { for { a <- wait.map(_ => 1) b <- wait.map(_ => 2) @@ -41,7 +41,7 @@ class ZQueryTests extends BaseZQueryTest { testWithTimeLimit("ZQuery comprehension 4", 1400) { val wait = ZQuery.fromZIO(ZIO.sleep(500.millis)) - ado { + parallelize { for { a <- wait.map(_ => 1) b <- wait.map(_ => 2) @@ -54,7 +54,7 @@ class ZQueryTests extends BaseZQueryTest { testWithTimeLimit("ZQuery comprehension 5", 1400) { val wait = ZQuery.fromZIO(ZIO.sleep(500.millis)) - ado { + parallelize { for { a <- wait.map(_ => 1) b <- wait.map(_ => 2)