Last active
March 10, 2022 14:24
-
-
Save frekw/abfd260aee62eb54d9918b5791837b5c to your computer and use it in GitHub Desktop.
This file contains 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
def foldZIO[A, E] = new PartialFoldZIO[A, E](()) | |
final class PartialFoldZIO[A, E](val unit: Unit) extends AnyVal { | |
def apply[R, E1, A0, B]( | |
onError: E => ZIO[R, E1, B], | |
onDefect: Throwable => ZIO[R, E1, B], | |
onSuccess: A => ZIO[R, E1, B], | |
): Middleware[R, E1, A0, A, A, B] = new Middleware[R, E1, A0, A, A, B] { | |
override def apply[R1 <: R, E2 >: E1](http: Http[R1, E2, A0, A]): Http[R1, E2, A0, B] = { | |
http.foldHttp( | |
e => Http.fromZIO(onError(e)), | |
t => Http.fromZIO(onDefect(t)), | |
a => Http.fromZIO(onSuccess(a)), | |
Http.empty, | |
) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment