kevin-lee / extras

A few extra tools

Home Page:https://extras.kevinly.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[`extras-cats`] Add `innerForeach` and `innerForeachF` to `EitherSyntax`

kevin-lee opened this issue · comments

Task

Summary

[extras-cats] Add innerForeach and innerForeachF to EitherSyntax

Project Details

Version: 0.38.0

Description

F[Either[A, B]].innerForeach(f: B => Unit) // F[Unit]
F[Either[A, B]].innerForeachF(f: B => F[Unit]) // F[Unit]
val foa: IO[Either[String, Int]] = IO(Right(123))
// IO[Either[String, Int]] = IO(Right(123))
foa.innerFoeach(println) // IO[Unit]
   .unsafeRunSync()
// 123 is printed and returns Unit
val foa: IO[Either[String, Int]] = IO(Left("Error"))
// IO[Either[String, Int]] = IO(Left("Error"))
foa.innerFoeach(println) // IO[Unit]
   .unsafeRunSync()
// Nothing happens
// returns Unit
val foa: IO[Either[String, Int]] = IO(Right(123))
// IO[Either[String, Int]] = IO(Right(123))
foa.innerFoeachF(n => IO(println(n))) // IO[Unit]
   .unsafeRunSync()
// 123 is printed and returns Unit
val foa: IO[Option[Int]] = IO(Left("Error"))
// IO[Either[String, Int]] = IO(Left("Error"))
foa.innerFoeachF(n => IO(println(n))) // IO[Unit]
   .unsafeRunSync()
// Nothing happens
// returns Unit