Skip to content

Instantly share code, notes, and snippets.

@tomatophobia
Created May 25, 2021 01:09
Show Gist options
  • Save tomatophobia/fc0eb6ac6b6fd6c68eb5274929a28822 to your computer and use it in GitHub Desktop.
Save tomatophobia/fc0eb6ac6b6fd6c68eb5274929a28822 to your computer and use it in GitHub Desktop.
/** A kleisli with a [[Request]] input and a [[Response]] output. This type
* is useful for writing middleware that are polymorphic over the return
* type F.
*
* @tparam F the effect type in which the [[Response]] is returned
* @tparam G the effect type of the [[Request]] and [[Response]] bodies
*/
type Http[F[_], G[_]] = Kleisli[F, Request[G], Response[G]]
/** A kleisli with a [[Request]] input and a [[Response]] output, such
* that the response effect is the same as the request and response bodies'.
* An HTTP app is total on its inputs. An HTTP app may be run by a server,
* and a client can be converted to or from an HTTP app.
*
* @tparam F the effect type in which the [[Response]] is returned, and also
* of the [[Request]] and [[Response]] bodies.
*/
type HttpApp[F[_]] = Http[F, F]
/** A kleisli with a [[Request]] input and a [[Response]] output, such
* that the response effect is an optional inside the effect of the
* request and response bodies. HTTP routes can conveniently be
* constructed from a partial function and combined as a
* `SemigroupK`.
*
* @tparam F the effect type of the [[Request]] and [[Response]] bodies,
* and the base monad of the `OptionT` in which the response is returned.
*/
type HttpRoutes[F[_]] = Http[OptionT[F, *], F]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment