Labra
Labra

Reputation: 1467

Convert a list of stream values to a stream of values with fs2

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.

Upvotes: 1

Views: 1542

Answers (1)

Labra
Labra

Reputation: 1467

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

 vs.traverse(f).map(s => Stream.emits(s).flatten) 

Upvotes: 2

Related Questions