Functional I/O in Scala
I/O is usually quite hard to tackle in a functional way. The predominant paradigm for I/O is the cursor. A cursor is a data structure that holds the current state of an I/O resource and provides a function to retrieve the next data available from that resource. This approach lacks some very properties we functional programmers care about:
- composability – Writing explicit I/O loops makes to hard to compose
- not functional – Ideally we write functions that transform input to output but pull based I/O (where you read the chunks) makes it hard to write pure functions
There are already libraries that provides some abstraction to overcome these shortcomings but somehow lacks in composability. In this presentation I will explore Enumeration based I/O with iteratee and how that makes I/O operations both functional and efficient. I will take some real world example use cases using Play framework where this approach has been used with success.
Come with your laptop running latest version of SBT. You can find the instructions right here: https://www.scala-sbt.org/#install