Created
September 28, 2022 15:44
-
-
Save debasishg/c86442189e29132841b7e274181d2506 to your computer and use it in GitHub Desktop.
ZIO Kleisli
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
package zio | |
case class ZKleisli[-R, +E, -A, +B]( | |
run: A => ZIO[R, E, B] | |
) { self => | |
// compose with a ZIO not lifted into a Kleisli | |
def mapZIO[R1 <: R, E1 >: E, A1 <: A, C1](bc: B => ZIO[R1, E1, C1]): ZKleisli[R1, E1, A, C1] = | |
ZKleisli(self.run(_).flatMap(bc)) | |
// Modify the output of the Kleisli function with `f` | |
def map[C](f: B => C): ZKleisli[R, E, A, C] = ZKleisli(self.run(_).map(f)) | |
// arrow composition tip to tail | |
def andThen[R1 <: R, E1 >: E, C]( | |
f: ZKleisli[R1, E1, B, C] | |
): ZKleisli[R1, E1, A, C] = | |
ZKleisli(self.run(_).flatMap(f.run(_))) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment