liveBook · Manning

Stream eliminator

As explained in Functional Programming in Scala, Second Edition

A stream eliminator is an operation that runs an incremental stream and converts its effects and outputs into a final result.

A stream eliminator runs an incremental Stream and turns its effects and outputs into a final result. Operations such as toList and run also determine how failures escape the stream: evaluating a Stream[Task, Int] can produce a Task failure wrapping the original exception. section 15.3.2

A failing stream

val s: Stream[Task, Int] = Stream.eval(Task("asdf".toInt)) Converting s with an eliminator such as toList or run yields a failed task whose error wraps NumberFormatException. Error handling can then be attached to the Stream or Pull before elimination. section 15.3.2

Elimination connects incremental computation to effect handling:

  • Stream uses Task as its effect, while Task supplies attempt and handleErrorWith for the error channel. section 15.3.2
  • Pull.step requires MonadThrow so errors can be interpreted while the stream is being stepped. section 15.3.2

How Functional Programming in Scala, Second Edition covers it

How deep it goes
Explains elimination through toList and run, then descends into error handling during Pull stepping.
Examples
Uses Stream.eval(Task("asdf".toInt)) and discusses toList or run producing a wrapped NumberFormatException.
What it assumes
Assumes Task, Stream, Pull, and monadic effect handling.
What you can do after
Operate a Stream by choosing an eliminator and handling failures through Stream or Pull error combinators.
How it connects
Connects Stream and Pull with Task, IO, Try, Either, and MonadThrow.

This explainer was generated by Manning's knowledge graph from the text of Functional Programming in Scala, Second Edition. The section links point to the parts of the book it draws on.