A comprehensive collection of exercises and solutions for learning ZIO — a Scala library for asynchronous and concurrent programming.
This repository serves as a hands-on companion to the Zionomicon Book, providing solutions to the exercises in each chapter.
ZIO is a zero-dependency Scala library that provides:
- Powerful async/concurrent runtime built on fibers (lightweight threads)
- Functional error handling with typed error channels
- Resource safety with automatic cleanup guarantees
- Dependency injection through type-level composition
- Software Transactional Memory (STM) for safe concurrent access
- Start with exercises: Look in
src/main/scala/zionomicon/exercises/for skeleton code with problem statements in Scaladoc comments - Attempt the exercises: Try to implement the solutions yourself
- Check solutions: Compare your work against
src/main/scala/zionomicon/solutions/ - Read explanations: Each solution includes detailed comments explaining the approach and key concepts
- Chapter 1: First steps with ZIO — basic effects, main function, error handling (Exercises | Solutions)
- Chapter 2: Testing ZIO programs — test assertions, test services (Exercises | Solutions)
- Chapter 3: The ZIO error model — typed errors, exception handling (Exercises | Solutions)
- Chapter 4: Essentials — integrating with ZIO, database operations, legacy code integration (Exercises | Solutions)
- Chapter 5: The fiber model — lightweight concurrency, fiber creation and inspection (Exercises | Solutions)
- Chapter 6: Concurrent operators — race, zip, foreach parallel execution (Exercises | Solutions)
- Chapter 8: Interruption in depth — cancellation, finalizers, safe shutdown (Exercises | Solutions)
- Chapter 9: Ref — shared mutable state with atomic operations (Exercises | Solutions)
- Chapter 10: Promise — one-time value publication and waiting (Exercises | Solutions)
- Chapter 11: Queue — FIFO work distribution between fibers (Exercises | Solutions)
- Chapter 12: Hub — broadcasting messages to multiple subscribers (Exercises | Solutions)
- Chapter 13: Semaphore — rate limiting and work constraints (Exercises | Solutions)
- Chapter 14: Acquire/release — safe resource handling in async code (Exercises | Solutions)
- Chapter 15: Scope — composable resource management (Exercises | Solutions)
- Chapter 17: Dependency injection essentials — R type parameter, layers (Exercises | Solutions)
- Chapter 19: Contextual data types — ZIO environment composition (Exercises | Solutions)
- Chapter 20: Configuring ZIO applications — configuration management (Exercises | Solutions)
- Chapter 21: STM composing atomicity — transactional effects (Exercises | Solutions)
- Chapter 22: STM data structures — TArray, TMap, TQueue, etc. (Exercises | Solutions)
- Chapter 23: STM performance — optimization and tradeoffs (Exercises | Solutions)
- Chapter 29: ZChannel — low-level channel abstraction, composing channels (Exercises | Solutions)
- Chapter 30: Transforming streams — mapping, filtering, folding stream data (Exercises | Solutions)
- Chapter 31: Combining streams — merging, zipping, and correlating multiple streams (Exercises | Solutions)
- Chapter 32: Streaming pipelines — building data processing pipelines with streams (Exercises | Solutions)
- Chapter 34: Schemas — the anatomy of data types, schema design patterns (Exercises | Solutions)
- Chapter 35: Communication protocols — ZIO HTTP, RESTful APIs, serialization (Exercises | Solutions)
- Chapter 24: Retries — schedules, exponential backoff, adaptive policies (Exercises | Solutions)
- Chapter 26: Best practices — design patterns and code organization (Exercises | Solutions)
- Chapter 37: ZIO runtime — executor configuration, thread pool management, runtime system (Exercises | Solutions)
- Chapter 39: Observability — metrics, monitoring, Prometheus and StatsD integration (Exercises | Solutions)
- Appendix C: Functional design — function composition, functional abstractions (Exercises | Solutions)
- Scala 2.13
- SBT (Simple Build Tool)
sbt compilesbt testsbt jmh:runThe project uses:
- ZIO 2.1.21 — Core async/concurrent runtime
- zio-config — Configuration management
- zio-http — HTTP server/client utilities
- zio-test — Testing framework
- zio-prelude — Validation and type safety utilities
- doobie — Database access (with SQLite driver)
- JMH — Benchmarking (Java Microbenchmark Harness)
See build.sbt for full dependency list.
This is a learning resource maintained in sync with the upstream Zionomicon. Contributions are welcome — fixes, additional exercises, and clarifications improve the learning experience for everyone.