Skip to content

Instantly share code, notes, and snippets.

@frekw
Last active March 10, 2022 14:24
Show Gist options
  • Save frekw/abfd260aee62eb54d9918b5791837b5c to your computer and use it in GitHub Desktop.
Save frekw/abfd260aee62eb54d9918b5791837b5c to your computer and use it in GitHub Desktop.
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