concept iteratee in category scala

This is an excerpt from Manning's book Play for Scala: Covers Play 2.
So far, we haven’t created an iteratee that actually produces something; we’ve relied on side effects of the method we gave to foreach. In general, though, an iteratee can produce a value when it’s done.
The Iteratee object exposes more methods that we can use to create iteratees. Suppose we want to build an iteratee that accepts Int chunks, and sums these chunks. We can do that as follows:
val summingIteratee = Iteratee.fold(0){ (sum: Int, chunk: Int) => sum + chunk }This works much like the fold method on any Scala collection. It takes two parameters: an initial value, in this case 0, and a function to compute a new value from the previous value and a new chunk. The iteratee that it creates will contain the value 0. When we feed it, say, a 5, it’ll compute a new value by summing its old value and the new 5, and then return a new iteratee with the value 5. If we then feed that new iteratee a 3, it’ll again produce a new iteratee, now with the value 8, and so forth.
We need another approach, where we can start using parts of the response as soon as they arrive in our application, without needing to wait for the entire response. And this is exactly what an iteratee can do. An iteratee is an object that receives each individual chunk of data and can do something with that data. This is shown in figure 10.3.
If we use the WS library with an iteratee, the response chunks aren’t buffered in a buffer that’s outside our control. Instead, an iteratee that’s a part of our application code and fully under our control receives all the chunks. The iteratee can do anything it wants with these chunks, or, rather, we can construct an iteratee and make it do whatever we want with the chunks.
When dealing with the Twitter streaming API, we’d want to use an iteratee that converts the HTTP response chunks into tweet objects, and send them to another part of our application, perhaps to be stored in a database. When that HTTP response chunk is dealt with, it can be discarded, and no buffer will be filled and run out of space eventually.
Iteratees are instances of the Iteratee class, and they can most easily be constructed using methods on the Iteratee object. As a first and simple example, we’ll create an iteratee that logs every chunk to the console.