Stream Processors
With input and output taken care of, we can fill in the gaps with more stream processors. The MapPipe we already wrote is pretty generic and modular, and in theory, the signature O => T can do a huge range of tasks, but it’s less ergonomic for functions that produce lists, options, or futures, all of which are better handled by specialized implementations. We can also work with custom stateful components and look at a few ways to get values out of them.
One of the most useful would be a component to take a value of type I, apply a function that produces an Option[O], and only pass the inner O on to destination pipes if the Option isn’t None. We can implement it with just a few lines of code, like this:
Get Modern Systems Programming with Scala Native now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.