anchor.diff:  Right now it may seem too much is going on. But as with every other paradigm, once we get a hands-on experience, we are going to feel comfortable working with it. The important conceptual thing to remember is that the left type `F` is responsible for closing resources and assigning operations to threads. In what follows, we are going to see examples of functional streams using the library *FS2*, a library that implements the above ideas.
   
   == How to Use FS2
  +
   This is how we use FS2 for reading a file...
   
   First we must add its dependencies:
  -[source,scala]
  -----
  +
  +```
   "co.fs2" %% "fs2-core" % "0.9.1",
   "co.fs2" %% "fs2-io" % "0.9.1",
  -----
  +```
   
   // optional I/O library
   
   Then, similar to Scala's `Future`, we must provide a strategy for execution:
  +
   [source,scala]
   ----
   implicit val strategy = Strategy.fromFixedDaemonPool(4)
   ----
  +
   Then we define the pipeline of transformations:
  +
   [source,scala]
  +----
   val lines: Stream[Task, String] = 
  -io.file.readAllAsync[Task](pathToFile, 4096) 
  -.through(text.utf8Decode)
  - .through(text.lines)
  +	io.file.readAllAsync[Task](pathToFile, 4096) 
  +						.through(text.utf8Decode)
  + 						.through(text.lines)
   ----
  -val lines: Stream[Task, String] =	io.file.readAllAsync[Task](pathToFile, 4096)` - we get a Stream[Task, Byte].through(text.utf8Decode)` - we get a Stream[Task, String], but newline is disregarded.through(text.lines)` - we get the final Stream[Task, String] representing lines.
  +
  +
  +`val lines: Stream[Task, String] =	io.file.readAllAsync[Task](pathToFile, 4096)` - we get a Stream[Task, Byte].through(text.utf8Decode)` - we get a Stream[Task, String], but newline is disregarded.through(text.lines)` - we get the final Stream[Task, String] representing lines.
   
   `Stream[F[_], O]` is the FS2 implementation of what we denoted by `Process[F[_],O]`.
   
  
positive.code: In this blog-post we are going to tackle those two problems and learn how to avoid imperative troublesome IO using a specialized Scala library - FS2 (previously known as Scalaz-Stream).
  
  == The Idea of Functional Streams
  The idea for solving the problem of resource-safety is to define a wrapper data type - `Process[F[_],O]`, where the left generic type `F` would know how to close the resource (the file) when it's needed. In that way we can guarantee resource-safety without having to do anything non-related to reading from file (such as handling an exception). We can think of `Process[F[_],O]` as a type that represents a *Stream builder*, possibly producing/using some side effect. For example when reading from file we would work with `Process[Task, String]`, where `Task` knows how to execute and handle an operation (by assigning it to a thread). But note that it doesn't start the execution immediately. It only starts when we call some of its executor-methods. Another example is when writing to output stream, in which case we  would use `Process[Task, Unit]`. Hence, we can say `Process[F[_],O]` is like a function `F[O] => Stream[O]`, but more powerful, and we will see exactly how is it more powerful.
  
  The idea for solving the second problem is *to separate the logic of computation from actual computation*. Note that the logic of how reading from file is done doesn't change through the course of our program's lifecycle. Only the result of executing that logic changes (since it involves a side-effect). So we are going to say that the left type - `F[O]` in `Process` knows how to evaluate effects. In that way we can represent our logic of computation, and delegate the responsibilities of executing that logic (and handling possible exceptions of the execution) to `F`. Most often we would substitute the generic type `F`  with  `Task` (which in addition allows concurrent composition of streams).
  
negative.code: 
  == Functional IO with FS2 Streams
  One of the main principles of functional programming is to avoid side-effects. For the most part, working with immutable instances would be sufficient to satisfy that principle. But sometimes it's needed to do some side effects e.g. when we want to read from file. One straight-forward way of doing it is to get a `BufferedSource`, and process it using an iterator as shown below. 
  
  [source,scala]
  ----
  def readFromFile(fileName: String) {
  	val src: BufferedSource = io.Source.fromFile(fileName)
  	val it: Iterator[String] = src.getLines 
  	val _ = while(it.hasNext) { 
  		val line = it.next()  
  		println(line)  
  	}  
  	src.close()
  }
  ----
  
  Then it is not too difficult to recursively convert the iterator to a Scala Stream of lines, without processing the whole iterator, using lazy evaluation. So we would end up with a function with signature:
  
  [source,scala]
  