I am working with some nested Stream
s and would like to use the for comprehension syntax with them:
def handleNestedStream(as : Stream[A]) : Stream[(A, B)] = {
a <- as
b <- makeBs(a)
} yield (a, b)
However, the makeBs
function returns an Option[Stream[B]]
. I would like the Option
to be unwrapped automatically. In addition, I would like the entire function to return None
if makeBs
fails. So the new function would look something like this:
def makeBs(a : A) : Option[Stream[B]] = { ... }
def handleNestedStream(as : Stream[A]) : Option[Stream[(A, B)]] = {
a <- as
b <- makeBs(a)
} yield (a, b)
The only change is the type of the function.
How can I accomplish something like this? Can StreamingT
from cats or StreamT
from scalaz help here?
Some of the types are flexible. makeBs
can be made to return Stream[Option[B]]
instead of Option[Stream[B]]
if that would make things simpler.
I need to use the scala standard lib Stream
type.