0

I would like to define a function with the following signature using fs2 Streams, cats EitherT and cats-effect IO.

def list2Stream[A,B,F[_],S](vs: List[A], 
                             f: A => EitherT[IO,S,Stream[IO,B]]
                             ): EitherT[IO,S,Stream[IO,B]] = {
   ???
}

which would map each value from vs to a stream of values and collect all those values in a new stream.

I tried something like:

  vs.map(f).sequence.flatten

but it seems there is no implicit definition for Stream.

Labra
  • 1,412
  • 1
  • 13
  • 33

1 Answers1

2

The following answer was provided in the gitter channel by Michael Pilquist:

 vs.traverse(f).map(s => Stream.emits(s).flatten) 
Labra
  • 1,412
  • 1
  • 13
  • 33