arrow-fx-coroutines / arrow.fx.coroutines.stream / Stream / zipWith

zipWith

fun <B, C> zipWith(other: Stream<B>, f: (O, B) -> C): Stream<C>

Deterministically zips elements using the specified function, terminating when the end of either branch is reached naturally.

import arrow.fx.coroutines.stream.*

//sampleStart
suspend fun main(): Unit =
  Stream(1, 2, 3)
  .zipWith(Stream(4, 5, 6, 7)) { acc, b -> acc + b }
  .toList()
  .let(::println) //[5, 7, 9]
//sampleEnd

Do you like Arrow?

Arrow Org
<