anchor.diff:  ----
   
   
  -=== Monad Transformers
  -
  -==== Motivation
  -
  -We can combine two functors and get a new one automatically. Given any two
  -functors _a_ and _b_, we can implement a generic `fmap` for the type _a (b Any)_,
  -we'll call it fmap2:
  -
  -[source, clojure]
  -----
  -(ns functor.example
  -  (:require [cats.core :refer [fmap]]
  -            [cats.builtin]
  -            [cats.monad.maybe :refer [just]]))
  -
  -(defn fmap2
  -  [f fv]
  -  (fmap (partial fmap f) fv))
  -
  -; Here, 'a' is [] and 'b' is Maybe, so the type of the
  -; combined functor is a vector of Maybe values that could
  -; contain a value of any type.
  -(fmap2 inc [(maybe/just 1) (maybe/just 2)])
  -;; => [#<Just 2> #<Just 3>]
  -----
  -
  -However, monads don't compose as nicely as functors do. We have to actually
  -implement the composition ourselves.
  -
  -In some circumstances we would like combine the effects of two monads into
  -another one. We call the resulting monad a monad transformer, which is the
  -composition of a "base" and "inner" monad. A monad transformer is itself a monad.
  -
  -
  -==== Using monad transformers
  -
  -Let's combine the effects of two monads: State and Maybe. We'll create the
  -transformer using State as the base monad since we want the resulting type to
  -be a stateful computation that may fail: `s -> Maybe (a, s)`.
  -
  -Almost every monad implemented in _cats_ has a monad transformer for combining
  -it with any other monad. The transformer functions take a Monad as their
  -argument and they return a reified MonadTrans:
  -
  -[source, clojure]
  -----
  -(ns transformers.example
  -  (:require [cats.core :as m]
  -            [cats.context :as ctx]
  -            [cats.monad.maybe :as maybe]
  -            [cats.labs.state :as state]))
  -
  -(def maybe-state
  -  (state/state-transformer maybe/context))
  -
  -(ctx/with-context maybe-state
  -  (state/run-state (m/return 42) {}))
  -;; => #<Just #<Pair [42 {}]>>
  -----
  -
  -As we can see in the example below, the return of the `maybe-state` monad creates
  -a stateful function that yields a Maybe containing a pair (value, next state).
  -
  -You probably noticed that we had to wrap the state function invocation with
  -`cats.context/with-context`. When working with monad transformers, we have to
  -be explicit about what monad we are using to implement the binding policy since
  -there is no way to distinguish values from a transformer type from those of
  -a regular monad.
  -
  -The `maybe-state` monad combines the semantics of both State and Maybe.
  -
  -
   == Types
   
   This section will take a tour over the types exposed in cats library and explain
  
positive.code: = Cats Documentation
  Andrey Antukh & Alejandro Gómez
  1.3.0
  :toc: left
  :!numbered:
  :idseparator: -
  
negative.code: [source, clojure]
  ----
  (require '[cats.core :as m])
  (require '[cats.labs.promise])
  (require '[promesa.core :as p])
  
  (defn sleep-promise
  