Created
February 27, 2020 12:36
-
-
Save qingwei91/db4a4070ef5367c9a9778251dec0c567 to your computer and use it in GitHub Desktop.
flatTap is interesting
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import $ivy.`org.typelevel::cats-effect:2.1.1` | |
import $ivy.`co.fs2::fs2-core:2.2.2` | |
import fs2._ | |
import cats.effect._ | |
import cats.implicits._ | |
val inputStream = Stream.emits[IO, Int](0 to 10) | |
def sideEffect(i:Int): Stream[IO, Int] = Stream.emits(1 to 3) | |
def ioPrint(x: Int): IO[Unit] = IO(println(x)) | |
inputStream.flatTap(sideEffect).evalMap(ioPrint).compile.toList.unsafeRunSync |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment