Recipe: Data-Driven Stream
val s = yourstream
def derive(sitem): A { ... }
// Derive some output from the first item in the streamm
s.take(1).flatMap(a => Stream.emits(derive(a), a)) ++ s.tailscala> val s = Stream.range(1,10)
s: fs2.Stream[Nothing,Int] = Segment(Emit(Chunk(()))).flatMap(<function1>)
scala> def derive(i: Int) = i+100
derive: (i: Int)Int
scala> s.pure.pull(h => h.receive1 { (a, h) => Pull.output1(derive(a)) >> Pull.output1(a) >> h.echo}).toVector
res0: Vector[Int] = Vector(101, 1, 2, 3, 4, 5, 6, 7, 8, 9)Last updated