O'Reilly logo

Scala Design Patterns - Second Edition by Ivan Nikolov

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

A more advanced monad example

The previous example was pretty simple, and it showed a great use of monads. We made our code much more straightforward, and we abstracted some logic inside the monads. Also, our code became much more readable than it was before.

In this subsection, let's see another use of monads, which is much more advanced this time. All the software we write becomes much more challenging and interesting whenever we add I/O to it. This can be reading and writing data to and from files, communicating with a user, making web requests, and so on. Monads can be used in order to write I/O applications in a purely functional way. There is a really important feature here: I/O has to deal with side effects, operations are usually ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required