Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 95 additions & 0 deletions docs/resources/migrating_from_monix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
---
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` | `Promise` |
| `Fiber` | `Fiber` |
| `MVar` | `Queue` |
| `Ref` | `Ref` |
| `Resource` | `ZManaged` |
| `Semaphore` | `Semaphore` |
| `TaskApp` | `App` |
| `TaskLocal` | `FiberRef` |
| `Task` | `Task` |

3 changes: 2 additions & 1 deletion website/sidebars.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@
},
"resources-sidebar": {
"Resources": [
"resources/resources"
"resources/resources",
"resources/migrating_from_monix"
]
},
"ecosystem-sidebar": {
Expand Down