{"id":13511304,"url":"https://github.com/ghostdogpr/zio-cheatsheet","last_synced_at":"2025-04-11T08:18:57.917Z","repository":{"id":40628550,"uuid":"182025649","full_name":"ghostdogpr/zio-cheatsheet","owner":"ghostdogpr","description":"ZIO Cheat Sheet","archived":false,"fork":false,"pushed_at":"2023-04-28T06:10:07.000Z","size":37,"stargazers_count":328,"open_issues_count":1,"forks_count":36,"subscribers_count":18,"default_branch":"master","last_synced_at":"2025-03-25T05:51:12.153Z","etag":null,"topics":["cheatsheet","scala","zio"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ghostdogpr.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null},"funding":{"github":"ghostdogpr"}},"created_at":"2019-04-18T06:01:29.000Z","updated_at":"2025-03-15T06:28:58.000Z","dependencies_parsed_at":"2024-01-12T20:03:37.755Z","dependency_job_id":null,"html_url":"https://github.com/ghostdogpr/zio-cheatsheet","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ghostdogpr%2Fzio-cheatsheet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ghostdogpr%2Fzio-cheatsheet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ghostdogpr%2Fzio-cheatsheet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ghostdogpr%2Fzio-cheatsheet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ghostdogpr","download_url":"https://codeload.github.com/ghostdogpr/zio-cheatsheet/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248360770,"owners_count":21090754,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cheatsheet","scala","zio"],"created_at":"2024-08-01T03:00:46.871Z","updated_at":"2025-04-11T08:18:57.897Z","avatar_url":"https://github.com/ghostdogpr.png","language":null,"funding_links":["https://github.com/sponsors/ghostdogpr"],"categories":["Scala","Others","CheatSheet"],"sub_categories":["Numpy"],"readme":"# ZIO Cheat Sheet\n\n- This is based on [ZIO](https://github.com/zio/zio) 2.0.X (in particular 2.0.10).\n- For simplicity, ZIO environment has been omitted but all the functions also work with the form `ZIO[R, E, A]`.\n- Function arguments are usually by name, but that has (mostly) been ignored for simplicity. Also, functions are often \"more generic\" in their parameter types than shown below.\n- For many functions there are several (unmentioned) related functions that are conceptually similar but differ in some detail. They are usually easy to learn due to consistent naming.\n- Important ZIO types other than the functional effect type `ZIO[R, E, A]` have been left out. For example: `ZStream[R, E, A]`, `ZLayer[RIn, E, ROut]`, `Fiber[E, A]` and `Ref[A]`.\n- In the remainder of this cheat sheet, `E1 \u003e: E`, but `E2` can be any error type. Also `A1 \u003e: A`.\n\n## Aliases\n\n| Alias        | Full Form                |\n| ------------ | ------------------------ |\n| `UIO[A]`     | `ZIO[Any, Nothing, A]`   |\n| `IO[E, A]`   | `ZIO[Any, E, A]`         |\n| `Task[A]`    | `ZIO[Any, Throwable, A]` |\n| `RIO[R, A]`  | `ZIO[R, Throwable, A]`   |\n| `URIO[R, A]` | `ZIO[R, Nothing, A]`     |\n\n## Creating effects\n\n| Name                                    | Given                                                                                   | To                                |\n| --------------------------------------- | --------------------------------------------------------------------------------------- | --------------------------------- |\n| ZIO.succeed                             | `=\u003e A`                                                                                  | `IO[Nothing, A]`                  |\n| ZIO.fail                                | `=\u003e E`                                                                                  | `IO[E, Nothing]`                  |\n| ZIO.interrupt                           |                                                                                         | `IO[Nothing, Nothing]`            |\n| ZIO.die                                 | `Throwable`                                                                             | `IO[Nothing, Nothing]`            |\n| ZIO.attempt                             | `=\u003e A`                                                                                  | `IO[Throwable, A]`                |\n| ZIO.async                               | `((IO[E, A] =\u003e Unit) =\u003e Unit)` \u003cbr\u003e FiberId                                             | `IO[E, A]`                        |\n| ZIO.fromEither                          | `Either[E, A]`                                                                          | `IO[E, A]`                        |\n| ZIO.left                                | `A`                                                                                     | `IO[Nothing, Either[A, Nothing]]` |\n| ZIO.right                               | `B`                                                                                     | `IO[Nothing, Either[Nothing, B]]` |\n| ZIO.fromFiber                           | `Fiber[E, A]`                                                                           | `IO[E, A]`                        |\n| ZIO.fromFuture                          | `ExecutionContext =\u003e Future[A]`                                                         | `IO[Throwable, A]`                |\n| ZIO.fromOption                          | `Option[A]`                                                                             | `IO[Option[Nothing], A]`          |\n| ZIO.none                                |                                                                                         | `IO[Nothing, Option[Nothing]]`    |\n| ZIO.some                                | `A`                                                                                     | `IO[Nothing, Option[A]]`          |\n| ZIO.fromTry                             | `Try[A]`                                                                                | `IO[Throwable, A]`                |\n| ZIO.acquireReleaseWith                  | `IO[E, A]` (acquire) \u003cbr\u003e `A =\u003e IO[Nothing, Any]` (release) \u003cbr\u003e `A =\u003e IO[E, B]` (use)  | `IO[E, B]`                        |\n| ZIO.when                                | `Boolean` \u003cbr\u003e `IO[E, A]`                                                               | `IO[E, Option[A]]`                |\n| ZIO.whenZIO                             | `IO[E, Boolean]` \u003cbr\u003e `IO[E, A]`                                                        | `IO[E, Option[A]]`                |\n| ZIO.whenCase                            | `A` \u003cbr\u003e `PartialFunction[A, IO[E, B]]`                                                 | `IO[E, Option[B]]`                |\n| ZIO.whenCaseZIO                         | `IO[E, A]` \u003cbr\u003e `PartialFunction[A, IO[E, B]]`                                          | `IO[E, Option[B]]`                |\n| ZIO.filter                              | `Iterable[A]` \u003cbr\u003e `A =\u003e IO[E, Boolean]`                                                | `IO[E, List[A]]`                  |\n| ZIO.cond                                | `Boolean` \u003cbr\u003e `A` \u003cbr\u003e `E`                                                             | `IO[E, A]`                        |\n\n## Transforming effects\n\n| Name               | From                     | Given                                   | To                       |\n| ------------------ | ------------------------ | --------------------------------------- | ------------------------ |\n| map                | `IO[E, A]`               | `A =\u003e B`                                | `IO[E, B]`               |\n| mapAttempt         | `IO[Throwable, A]`       | `A =\u003e B`                                | `IO[Throwable, B]`       |\n| as                 | `IO[E, A]`               | `B`                                     | `IO[E, B]`               |\n| asSome             | `IO[E, A]`               |                                         | `IO[E, Option[A]]`       |\n| asSomeError        | `IO[E, A]`               |                                         | `IO[Option[E], A]`       |\n| orElseFail         | `IO[E, A]`               | `E2`                                    | `IO[E2, A]`              |\n| unit               | `IO[E, A]`               |                                         | `IO[E, Unit]`            |\n| flatMap            | `IO[E, A]`               | `A =\u003e IO[E1, B]`                        | `IO[E1, B]`              |\n| flatten            | `IO[E, IO[E1, A]]`       |                                         | `IO[E1, A]`              |\n| mapBoth            | `IO[E, A]`               | `E =\u003e E2` \u003cbr\u003e `A =\u003e B`                 | `IO[E2, B]`              |\n| mapError           | `IO[E, A]`               | `E =\u003e E2`                               | `IO[E2, A]`              |\n| mapErrorCause      | `IO[E, A]`               | `Cause[E] =\u003e Cause[E2]`                 | `IO[E2, A]`              |\n| flatMapError       | `IO[E, A]`               | `E =\u003e IO[Nothing, E2]`                  | `IO[E2, A]`              |\n| collect            | `IO[E, A]`               | `E1` \u003cbr\u003e `PartialFunction[A, B]`       | `IO[E1, B]`              |\n| sandbox            | `IO[E, A]`               |                                         | `IO[Cause[E], A]`        |\n| flip               | `IO[E, A]`               |                                         | `IO[A, E]`               |\n| tap                | `IO[E, A]`               | `A =\u003e IO[E1, _]`                        | `IO[E1, A]`              |\n| tapBoth            | `IO[E, A]`               | `E =\u003e IO[E1, _]` \u003cbr\u003e `A =\u003e IO[E1, _]`  | `IO[E1, A]`              |\n| tapError           | `IO[E, A]`               | `E =\u003e IO[E1, _]`                        | `IO[E1, A]`              |\n| absolve            | `IO[E, Either[E, A]]`    |                                         | `IO[E, A]`               |\n| some               | `IO[E, Option[A]]`       |                                         | `IO[Option[E], A]`       |\n| head               | `IO[E, List[A]]`         |                                         | `IO[Option[E], A]`       |\n| toFuture           | `IO[Throwable, A]`       |                                         | `IO[Nothing, Future[A]]` |\n| filterOrDie        | `IO[E, A]`               | `A =\u003e Boolean` \u003cbr\u003e `Throwable`         | `IO[E, A]`               |\n| filterOrDieMessage | `IO[E, A]`               | `A =\u003e Boolean` \u003cbr\u003e `String`            | `IO[E, A]`               |\n| filterOrElse       | `IO[E, A]`               | `A =\u003e Boolean` \u003cbr\u003e `A =\u003e IO[E, A]`     | `IO[E, A]`               |\n| filterOrFail       | `IO[E, A]`               | `A =\u003e Boolean` \u003cbr\u003e `E`                 | `IO[E, A]`               |\n| when               | `IO[E, A]`               | `Boolean`                               | `IO[E, Option[A]]`       |\n| unless             | `IO[E, A]`               | `Boolean`                               | `IO[E, Option[A]]`       |\n\n## Declaring and providing the environment\n\n| Name               | From                     | Given                                   | To                       |\n| ------------------ | ------------------------ | --------------------------------------- | ------------------------ |\n| ZIO.service        |                          | `given Tag[A]`                          | `ZIO[A, Nothing, A]`     |\n| provideEnvironment | `ZIO[R, E, A]`           | `ZEnvironment[R]`                       | `IO[E, A]`               |\n| provideLayer       | `ZIO[R, E, A]`           | `ZLayer[R0, E, R]`                      | `ZIO[R0, E, A]`          |\n\n## Configuration\n\n| Name               | From                     | Given                                   | To                       |\n| ------------------ | ------------------------ | --------------------------------------- | ------------------------ |\n| ZIO.config         |                          | `Config[A]`                             | `IO[Config.Error, A]`    |\n\n## Recover from errors\n\n| Name          | From       | Given                                         | To                          |\n| ------------- | ---------- | --------------------------------------------- | --------------------------- |\n| either        | `IO[E, A]` |                                               | `IO[Nothing, Either[E, A]]` |\n| option        | `IO[E, A]` |                                               | `IO[Nothing, Option[A]]`    |\n| ignore        | `IO[E, A]` |                                               | `IO[Nothing, Unit]`         |\n| exit          | `IO[E, A]` |                                               | `IO[Nothing, Exit[E, A]]`   |\n| `\u003c\u003e` (orElse) | `IO[E, A]` | `IO[E2, A1]`                                  | `IO[E2, A1]`                |\n| orElseEither  | `IO[E, A]` | `IO[E2, B]`                                   | `IO[E2, Either[A, B]]`      |\n| fold          | `IO[E, A]` | `E =\u003e B` \u003cbr\u003e `A =\u003e B`                        | `IO[Nothing, B]`            |\n| foldZIO       | `IO[E, A]` | `E =\u003e IO[E2, B]` \u003cbr\u003e `A =\u003e IO[E2, B]`        | `IO[E2, B]`                 |\n| foldCauseZIO  | `IO[E, A]` | `Cause[E] =\u003e IO[E2, B]` \u003cbr\u003e `A =\u003e IO[E2, B]` | `IO[E2, B]`                 |\n| catchAll      | `IO[E, A]` | `E =\u003e IO[E2, A1]`                             | `IO[E2, A1]`                |\n| catchAllCause | `IO[E, A]` | `Cause[E] =\u003e IO[E2, A1]`                      | `IO[E2, A1]`                |\n| catchSome     | `IO[E, A]` | `PartialFunction[E, IO[E1, A1]]`              | `IO[E1, A1]`                |\n| retry         | `IO[E, A]` | `Schedule[E, S]`                              | `IO[E, A]`                  |\n| eventually    | `IO[E, A]` |                                               | `IO[Nothing, A]`            |\n\n## Terminate fiber with errors\n\n| Name              | From               | Given                                           | To                          |\n| ----------------- | ------------------ | ----------------------------------------------- | --------------------------- |\n| orDie             | `IO[Throwable, A]` |                                                 | `IO[Nothing, A]`            |\n| orDieWith         | `IO[E, A]`         | `E =\u003e Throwable`                                | `IO[Nothing, A]`            |\n| refineOrDie       | `IO[Throwable, A]` | `PartialFunction[Throwable, E2]`                | `IO[E2, A]`                 |\n| refineOrDieWith   | `IO[E, A]`         | `PartialFunction[E, E2]` \u003cbr\u003e `E =\u003e Throwable`  | `IO[E2, A]`                 |\n\n## Combining effects + parallelism\n\n| Name               | From       | Given                                            | To                               |\n| ------------------ | ---------- | ------------------------------------------------ | -------------------------------- |\n| ZIO.foldLeft       |            | `Iterable[A]` \u003cbr\u003e `S` \u003cbr\u003e `(S, A) =\u003e IO[E, S]` | `IO[E, S]`                       |\n| ZIO.foreach        |            | `Iterable[A]` \u003cbr\u003e `A =\u003e IO[E, B]`               | `IO[E, List[B]]`                 |\n| ZIO.foreachPar     |            | `Iterable[A]` \u003cbr\u003e `A =\u003e IO[E, B]`               | `IO[E, List[B]]`                 |\n| ZIO.collectAll     |            | `Iterable[IO[E, A]]`                             | `IO[E, List[A]]`                 |\n| ZIO.collectAllPar  |            | `Iterable[IO[E, A]]`                             | `IO[E, List[A]]`                 |\n| ZIO.forkAll        |            | `Iterable[IO[E, A]]`                             | `IO[Nothing, Fiber[E, List[A]]]` |\n| fork               | `IO[E, A]` |                                                  | `IO[Nothing, Runtime[E, A]]`     |\n| `\u003c*\u003e` (zip)        | `IO[E, A]` | `IO[E1, B]`                                      | `IO[E1, (A, B)]`                 |\n| `*\u003e` (zipRight)    | `IO[E, A]` | `IO[E1, B]`                                      | `IO[E1, B]`                      |\n| `\u003c*` (zipLeft)     | `IO[E, A]` | `IO[E1, B]`                                      | `IO[E1, A]`                      |\n| `\u003c\u0026\u003e` (zipPar)     | `IO[E, A]` | `IO[E1, B]`                                      | `IO[E1, (A, B)]`                 |\n| `\u0026\u003e` (zipParRight) | `IO[E, A]` | `IO[E1, B]`                                      | `IO[E1, B]`                      |\n| `\u003c\u0026` (zipParLeft)  | `IO[E, A]` | `IO[E1, B]`                                      | `IO[E1, A]`                      |\n| race               | `IO[E, A]` | `IO[E1, A1]`                                     | `IO[E1, A1]`                     |\n| raceAll            | `IO[E, A]` | `Iterable[IO[E1, A1]]`                           | `IO[E1, A1]`                     |\n| raceEither         | `IO[E, A]` | `IO[E1, B]`                                      | `IO[E1, Either[A, B]]`           |\n\n## Finalizers\n\n| Name          | From       | Given                      | To         |\n| ------------- | ---------- | -------------------------- | ---------- |\n| ensuring      | `IO[E, A]` | `UIO[_]`                   | `IO[E, A]` |\n| onError       | `IO[E, A]` | `Cause[E] =\u003e UIO[_]`       | `IO[E, A]` |\n| onInterrupt   | `IO[E, A]` | `UIO[_]`                   | `IO[E, A]` |\n| onTermination | `IO[E, A]` | `Cause[Nothing] =\u003e UIO[_]` | `IO[E, A]` |\n\n## Timing and repetition\n\n| Name        | From       | Given            | To                             |\n| ----------- | ---------- | ---------------- | ------------------------------ |\n| ZIO.never   |            |                  | `IO[Nothing, Nothing]`         |\n| ZIO.sleep   |            | `Duration`       | `IO[Nothing, Unit]`            |\n| delay       | `IO[E, A]` | `Duration`       | `IO[E, A]`                     |\n| timeout     | `IO[E, A]` | `Duration`       | `IO[E, Option[A]]`             |\n| timed       | `IO[E, A]` |                  | `IO[E, (Duration, A)]`         |\n| forever     | `IO[E, A]` |                  | `IO[E, Nothing]`               |\n| repeat      | `IO[E, A]` | `Schedule[A, B]` | `IO[E, B]`                     |\n| repeatUntil | `IO[E, A]` | `A =\u003e Boolean`   | `IO[E, A]`                     |\n| repeatWhile | `IO[E, A]` | `A =\u003e Boolean`   | `IO[E, A]`                     |\n\n## Logging\n\n| Name            | From       | Given            | To                             |\n| --------------- | ---------- | ---------------- | ------------------------------ |\n| ZIO.log         |            | `String`         | `IO[Nothing, Unit]`            |\n| ZIO.logFatal    |            | `String`         | `IO[Nothing, Unit]`            |\n| ZIO.logError    |            | `String`         | `IO[Nothing, Unit]`            |\n| ZIO.logWarning  |            | `String`         | `IO[Nothing, Unit]`            |\n| ZIO.logInfo     |            | `String`         | `IO[Nothing, Unit]`            |\n| ZIO.logDebug    |            | `String`         | `IO[Nothing, Unit]`            |\n| ZIO.logTrace    |            | `String`         | `IO[Nothing, Unit]`            |\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fghostdogpr%2Fzio-cheatsheet","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fghostdogpr%2Fzio-cheatsheet","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fghostdogpr%2Fzio-cheatsheet/lists"}