Essential Effects

Adam Rosien

How to safely create, compose, and execute effectful Scala programs using the Typelevel Cats Effect library.

NEW! Completely rewritten to use Cats Effect 3!

Early access is available now!

What people are saying:

If you’re at all interested in FP in Scala, buy Essential Effects by @arosien — it’s a fantastic overview of Cats Effect!

I can confirm that Essential Effects is really good. A great practical guide to Cats Effect.

Dave Gurnell, author of "Creative Scala", "Essential Scala" and "Scala with Cats"

If you do #Scala this is a *must buy*. Go for it. If you miss it, you'll regret it!

Can confirm this book is legit. I'd easily recommend it to anybody getting into Scala or wanting to learn pure functional programming with Cats Effect.

I've been working through a reviewer copy and it's great. Full of stuff I wish I had in one place when I was learning this. Plenty of things I missed and have now learned.

This [...] is exactly the kind of introduction to concurrency I wish I had had :)

Guillaume Bogard, functional programmer, speaker and trainer

Describing IO like that really helped me understand it!

Marc Ramírez Invernon, Scala & Spark Barcelona Meetup co-organizer

Essential Effects is now available for early access.

Buy the book!
When the final version is published, you'll receive a copy for no additional cost.

Want to read an excerpt before you buy?

Sign up to the newsletter to stay updated on the book's progress.

We'll never share your email with anyone else. Powered by Buttondown.

Cats Effect is a Scala library that makes it easy to write code that effectively uses multiple cores and doesn’t leak resources. This makes building complex applications, such as highly concurrent services, much more productive. Essential Effects aims to introduce the core concepts in Cats Effect, giving you the knowledge you need to go further with the library in your own applications.

This book is for you if:

Essential Effects will teach you to:

Feel free to read an excerpt before you buy!


Want help learning about effects? Inner Product LLC offers a companion training course to the book.

About the Author

Programming in Scala since 2011, Adam focuses on building systems, teaching, and mentoring using functional programming as a Principal at Inner Product LLC. He previously helped various startups in many domains develop back-end systems and implement continuous deployment practices, and also spent five years as a developer at Xerox PARC. This is his first book.

Table of Contents

  1. Preface
    • Acknowledgements
    • About this book
    • Cats Effect versions
    • Source code for examples and exercises
    • Prerequisites
  2. Chapter 1. Effects: evaluation and execution
    • The substitution model of evaluation
    • Dealing with side-effects
    • The Effect Pattern
    • Capturing arbitrary side-effects as an effect
    • Composing effects
    • Summary
  3. Chapter 2. Cats Effect IO
    • Constructing IO values
    • Transforming IO values
    • Executing IO values
    • IO as an effect
    • Executing effects in applications with IOApp
    • Summary
  4. Chapter 3. Parallel execution
    • Does IO support parallelism?
    • The Parallel typeclass
    • Inspecting parallelism
    • parMapN
    • parTraverse
    • parSequence
    • Summary
  5. Chapter 4. Concurrent control
    • Decomposing the behavior of parMapN
    • Gaining control with Fiber
    • Canceling a running Fiber
    • Racing multiple effects
    • Summary
  6. Chapter 5. Shifting contexts
    • How much parallelism can we get?
    • The need for multiple contexts
    • Contexts for I/O-bound actions
    • How do you know something is blocking?
    • Finer-grained control of contexts
    • Example: contexts for database access in Doobie
    • Summary
  7. Chapter 6. Integrating asynchrony
    • Asynchronous callbacks
    • Integrating with Future
    • Summary
  8. Chapter 7. Managing resources
    • Creating a Resource to manage state
    • Composing managed state
    • Resources for dependency management
    • Summary
  9. Chapter 8. Testing Effects
    • Assertions on effectful values
    • Testing effect scheduling by controlling its dependencies
    • Summary
  10. Chapter 9. Concurrent coordination
    • Atomic updates with Ref
    • Write-once synchronization with Deferred
    • Concurrent state machines
    • Summary
  11. Chapter 10. Case study: job scheduler
    • Jobs
    • Job Scheduler
    • Reacting to job state changes
    • Putting everything together
    • Summary
  12. Chapter 11. Conclusion
    • Next steps
  13. Glossary
  14. Appendix A: Cheatsheets
  15. Appendix B: Abstracting effects with typeclasses
  16. Appendix C: Solutions to selected exercises
  17. References

© 2021-2024 Inner Product LLC