From 1c9a00b91f0c73eec67ebbf866ff0af69979bab5 Mon Sep 17 00:00:00 2001 From: Kit Langton Date: Sat, 20 Mar 2021 12:58:14 -0700 Subject: [PATCH 1/3] add migrating from monix guide --- docs/resources/migrating_from_monix.md | 93 ++++++++++++++++++++++++++ website/sidebars.json | 3 +- 2 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 docs/resources/migrating_from_monix.md diff --git a/docs/resources/migrating_from_monix.md b/docs/resources/migrating_from_monix.md new file mode 100644 index 000000000000..0e68d9d3cc42 --- /dev/null +++ b/docs/resources/migrating_from_monix.md @@ -0,0 +1,93 @@ +--- +id: migrating_from_monix +title: "Migrating from Monix to ZIO" +--- + +Monix's `Task[A]` can be easily replaced with ZIO's `Task[A]` (an alias for `ZIO[Any, Throwable, A]`). +Translation should be relatively straightfoward. Below, you'll find tables showing the ZIO equivalents of + `monix.eval.Task`'s methods. + +Once you've completed the initial translation, you'll find that ZIO is outfitted with many additional +methods which have no Monix equivalents, so have fun exploring the API and see if you can rewrite some +of your logic at a higher level of abstraction, with more powerful combinators and fewer lines code. + +### Methods on Trait + +| Monix | ZIO | +|-------|-----| +| `attempt` | `either` | +| `bracketCase` | `bracketExit` | +| `bracketE` | `bracketExit` | +| `bracket` | `bracket` | +| `delayExecution` | `delay` | +| `dematerialize` | `absolve` | +| `doOnCancel` | `onInterrupt` | +| `doOnFinish` | `onExit` | +| `failed` | `flip` | +| `flatMap` | `flatMap` | +| `flatten` | `flatten` | +| `guaranteeCase` | `ensuringExit` | +| `guarantee` | `ensuring` | +| `loopForever` | `forever` | +| `materialize` | `either` | +| `memoize` | `memoize` | +| `onErrorFallbackTo` | `orElse` | +| `onErrorHandleWith` | `catchAll` | +| `onErrorRecoverWith` | `catchSome` | +| `onErrorRestart` | `retryN` | +| `redeemWith` | `foldM` | +| `redeem` | `fold` | +| `restartUntil` | `repeatUntil` | +| `start` | `fork` | +| `timed` | `timed` | +| `timeout` | `timeout` | +| `uncancelable` | `uninterruptible` | + +### Methods on Companion Object + +| Monix | ZIO | +|-------|-----| +| `apply` | `apply` | +| `asyncF` | `effectAsyncM` | +| `async` | `effectAsync` | +| `cancelable` | `effectAsyncInterrupt` | +| `deferFuture` | `fromFuture` | +| `defer` | `effectSuspend` | +| `delay` | `effect` | +| `eval` | `effect` | +| `fromEither` | `fromEither` | +| `fromFuture` | `fromFuture` | +| `fromTry` | `fromTry` | +| `map2` | `mapN` | +| `mapBoth` | `mapParN` | +| `never` | `never` | +| `now` | `succeed` | +| `parMap2` | `mapParN` | +| `parSequenceN` | `collectAllParN` | +| `parSequence` | `collectAllPar` | +| `parTraverseN` | `foreachParN` | +| `parTraverse` | `foreachPar` | +| `parZip2` | `tupledPar` | +| `pure` | `succeed` | +| `racePair` | `raceWith` | +| `race` | `raceFirst` | +| `raiseError` | `fail` | +| `sequence` | `collectAll` | +| `shift` | `yield` | +| `sleep` | `sleep` | +| `suspend` | `effectSuspend` | +| `traverse` | `foreach` | +| `unit` | `unit` | + +### Data Structures + +| Monix / Cats Effect | ZIO | +|-------|-----| +| `Deferred` | `Deferred` | +| `Fiber` | `Fiber` | +| `MVar` | `Queue` | +| `Ref` | `Ref` | +| `Resource` | `ZManaged` | +| `Semaphore` | `Semaphore` | +| `TaskApp` | `App` | +| `Task` | `Task` | diff --git a/website/sidebars.json b/website/sidebars.json index 743c70d39ef2..592a3e5139f9 100644 --- a/website/sidebars.json +++ b/website/sidebars.json @@ -83,7 +83,8 @@ }, "resources-sidebar": { "Resources": [ - "resources/resources" + "resources/resources", + "resources/migrating_from_monix" ] }, "ecosystem-sidebar": { From fce76796b01cdff955197cf0e2794ece23226155 Mon Sep 17 00:00:00 2001 From: Kit Langton Date: Sat, 20 Mar 2021 21:45:28 -0700 Subject: [PATCH 2/3] Update docs/resources/migrating_from_monix.md Co-authored-by: Itamar Ravid --- docs/resources/migrating_from_monix.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/resources/migrating_from_monix.md b/docs/resources/migrating_from_monix.md index 0e68d9d3cc42..5da8f17b58fb 100644 --- a/docs/resources/migrating_from_monix.md +++ b/docs/resources/migrating_from_monix.md @@ -83,7 +83,7 @@ of your logic at a higher level of abstraction, with more powerful combinators a | Monix / Cats Effect | ZIO | |-------|-----| -| `Deferred` | `Deferred` | +| `Deferred[Task, A]` | `Promise[Throwable, A]` | | `Fiber` | `Fiber` | | `MVar` | `Queue` | | `Ref` | `Ref` | From ed0c8b49bcf01bb6ca71328bb751178bf5c25807 Mon Sep 17 00:00:00 2001 From: Kit Langton Date: Tue, 23 Mar 2021 19:13:20 -0700 Subject: [PATCH 3/3] Update migrating_from_monix.md --- docs/resources/migrating_from_monix.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/resources/migrating_from_monix.md b/docs/resources/migrating_from_monix.md index 5da8f17b58fb..30211235309d 100644 --- a/docs/resources/migrating_from_monix.md +++ b/docs/resources/migrating_from_monix.md @@ -83,11 +83,13 @@ of your logic at a higher level of abstraction, with more powerful combinators a | Monix / Cats Effect | ZIO | |-------|-----| -| `Deferred[Task, A]` | `Promise[Throwable, A]` | +| `Deferred` | `Promise` | | `Fiber` | `Fiber` | | `MVar` | `Queue` | | `Ref` | `Ref` | | `Resource` | `ZManaged` | | `Semaphore` | `Semaphore` | | `TaskApp` | `App` | +| `TaskLocal` | `FiberRef` | | `Task` | `Task` | +