Created
November 23, 2018 08:23
-
-
Save ScalaWilliam/9fb19ea6153c1e25865e4d91b30614e4 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 of[F[_]](pf: PartialFunction[Request[F], HttpRoutes[F]])( | |
implicit F: Sync[F]): HttpRoutes[F] = { | |
Kleisli { req: Request[F] => | |
OptionT.fromOption[F](pf.lift(req).map(_.apply(req))).flatMap(identity) | |
} | |
} | |
// but we'd like to do multiple PartialFunctions here actually? | |
// and a PF is already a Kleisli of Option | |
def apply[F[_]: Monad, UserId]( | |
f: Kleisli[F, Request[F], Option[HttpRoutes[F]]]): HttpRoutes[F] = { | |
Kleisli { request: Request[F] => | |
OptionT | |
.liftF(f(request)) | |
.map(_.map(_.apply(request))) | |
.flatMap(x => OptionT.fromOption[F](x)) | |
.flatMap(identity) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment