Skip to content

Commit

Permalink
Add BIOError.tapError
Browse files Browse the repository at this point in the history
  • Loading branch information
neko-kai committed Nov 13, 2019
1 parent 689401f commit 62aa18c
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 1 deletion.
Expand Up @@ -66,6 +66,7 @@ trait BIOError[F[+_ ,+_]] extends BIOGuarantee[F] {
@inline def attempt[E, A](r: F[E, A]): F[Nothing, Either[E, A]] = redeemPure(r)(Left(_), Right(_))
@inline def catchAll[E, A, E2, A2 >: A](r: F[E, A])(f: E => F[E2, A2]): F[E2, A2] = redeem(r)(f, pure)
@inline def flip[E, A](r: F[E, A]) : F[A, E] = redeem(r)(pure, fail(_))
@inline def tapError[E, E1 >: E, A](r: F[E, A])(f: E => F[E1, Unit]): F[E1, A] = catchAll(r)(e => *>(f(e), fail(e)))

// defaults
@inline override def bimap[E, A, E2, B](r: F[E, A])(f: E => E2, g: A => B): F[E2, B] = redeem(r)(e => fail(f(e)), a => pure(g(a)))
Expand Down
Expand Up @@ -79,7 +79,7 @@ object BIOSyntax {
@inline final def redeem[E2, B](err: E => F[E2, B], succ: A => F[E2, B]): F[E2, B] = F.redeem[E, A, E2, B](r)(err, succ)
@inline final def redeemPure[B](err: E => B, succ: A => B): F[Nothing, B] = F.redeemPure(r)(err, succ)

@inline final def tapError[E1 >: E](f: E => F[E1, Unit]): F[E1, A] = F.catchAll(r)(e => F.*>(f(e), F.fail(e)))
@inline final def tapError[E1 >: E](f: E => F[E1, Unit]): F[E1, A] = F.tapError[E, E1, A](r)(f)

@inline final def attempt: F[Nothing, Either[E, A]] = F.attempt(r)

Expand Down
Expand Up @@ -27,6 +27,7 @@ class BIOZio[R] extends BIO[ZIO[R, +?, +?]] {
@inline override final def void[E, A](r: IO[E, A]): IO[E, Unit] = r.unit
@inline override final def map[E, A, B](r: IO[E, A])(f: A => B): IO[E, B] = r.map(f)

@inline override final def tapError[E, E1 >: E, A](r: ZIO[R, E, A])(f: E => ZIO[R, E1, Unit]): ZIO[R, E1, A] = r.tapError(f)
@inline override final def leftMap[E, A, E2](r: IO[E, A])(f: E => E2): IO[E2, A] = r.mapError(f)
@inline override final def leftFlatMap[E, A, E2](r: IO[E, A])(f: E => IO[Nothing, E2]): IO[E2, A] = r.flatMapError(f)
@inline override final def flip[E, A](r: IO[E, A]): IO[A, E] = r.flip
Expand Down

0 comments on commit 62aa18c

Please sign in to comment.