A Pipe names an independent stream transformation: a function that accepts a stream of input values and produces a stream of output values. The name adds no expressiveness, but makes transformations easier to describe, reuse, and compose. section 15.2.2
Build pipes as ordinary values, then compose or apply them like functions:
- Define focused transformations such as nonEmpty, which filters empty strings, and lowerCase, which maps each string to lowercase. section 15.2.2
- Compose transformations with function composition: normalize = nonEmpty andThen lowerCase. section 15.2.2 section 15.6
- Apply a pipe directly as normalize(lines), or use scala.util.chaining.pipe to write lines.pipe(normalize). section 15.2.2
- Generalize the alias to Pipe[F, I, O] when streams may evaluate effects of F while transforming inputs I into outputs O. section 15.3 section 15.6
Converting input lines
A conversion pipeline gives each step one responsibility: trim lines, remove empty lines and comments, parse valid numbers, then convert them to Celsius. Composing these steps yields a Pipe[String, Double] that can process file input before folding the results into an output file. section 15.6
type Pipe[-I, +O] = Stream[I] => Stream[O]
The core type alias makes the abstraction concrete: Pipe[-I, +O] = Stream[I] => Stream[O]. section 15.2.2
