13 External effects and I/O
This chapter covers
- Segregating pure functions from effects in a program
- Separating effectful concerns using an I/O data type
- Hiding effectful code in data type abstractions
- Implementing a free monad for flexible I/O delegation
This chapter continues from what we’ve learned so far about monads and algebraic data types and extends them to handle external effects like interacting with databases or the console, or reading and writing to files. We develop a monad called IO
with the specific purpose of dealing with such I/O effects in a purely functional way.
We’ll make an essential distinction in this chapter between effects and side effects. The IO
monad provides a straightforward way of embedding imperative programming ...
Get Functional Programming in Kotlin 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.