50 The IO type
After reading this lesson, you will be able to
- Represent synchronous and asynchronous side effects lazily
- Execute and process their result
Now that you’ve mastered the difference between eager and lazy evaluation, you are going to learn about cats.effect.IO
. Impure functions produce side effects. The type IO
, which is part of the cats-effect library, allows you to represent synchronous and asynchronous side effects lazily. You’ll be able to separate the definition of what to execute from its actual execution, making it easier to maintain and test. You can consider the type IO
as the lazy alternative to the eagerly evaluated Future
. After discussing why lazily evaluating side effects can be advantageous, you’ll see how to represent ...
Get Get Programming with Scala now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.