flatMap

flatMap

Stream("abc")
  .flatMap { str =>
    Stream.emits(str.toList)
  }
  .compile
  .toList

diagram

flatMap (with chunks)

Stream("abc")
  .flatMap { str =>
    Stream.emits(str.toList)
  }
  .compile
  .toList

diagram

error propagation

Stream("abc")
  .flatMap { _ =>
    Stream.raiseError[IO](Err)
  }
  .compile
  .toList

diagram

error propagation (with chunks)

Stream("abc")
  .flatMap { _ =>
    Stream.raiseError[IO](Err)
  }
  .compile
  .toList

diagram

error handling

Stream("abc")
  .flatMap { _ =>
    Stream.raiseError[IO](Err)
  }
  .handleError(_ => 'a')
  .compile
  .toList

diagram

error handling (with chunks)

Stream("abc")
  .flatMap { _ =>
    Stream.raiseError[IO](Err)
  }
  .handleError(_ => 'a')
  .compile
  .toList

diagram

bracket

Stream('a', 'b', 'c')
  .flatMap { x =>
    Stream.bracket(IO(s"<$x"))(_ => IO(s"$x>").void)
  }
  .compile
  .toList

diagram

bracket (with chunks)

Stream('a', 'b', 'c')
  .flatMap { x =>
    Stream.bracket(IO(s"<$x"))(_ => IO(s"$x>").void)
  }
  .compile
  .toList

diagram