    {-# LANGUAGE BangPatterns               #-}
    {-# LANGUAGE CPP                        #-}
    {-# LANGUAGE FlexibleContexts           #-}
    {-# LANGUAGE FlexibleInstances          #-}
    {-# LANGUAGE GeneralizedNewtypeDeriving #-}
    {-# LANGUAGE ImpredicativeTypes         #-}
    {-# LANGUAGE MultiParamTypeClasses      #-}
    {-# LANGUAGE OverloadedStrings          #-}
    {-# LANGUAGE TemplateHaskell            #-}
    {-# LANGUAGE TypeFamilies               #-}

    #ifndef MIN_VERSION_comonad
    #define MIN_VERSION_comonad(x,y,z) 1
    #endif

    module Snap.Snaplet.Internal.Types where

    ------------------------------------------------------------------------------
    import           Control.Applicative          (Alternative)
    import           Control.Lens                 (ALens', makeLenses, set)
    import           Control.Monad                (liftM)
    import           Control.Monad.Base           (MonadBase (..))
    import           Control.Monad.Fail           (MonadFail)
    import           Control.Monad.Reader         (MonadIO (..), MonadPlus, MonadReader (ask, local))
    import           Control.Monad.State.Class    (MonadState (get, put), gets)
    import           Control.Monad.Trans.Control  (MonadBaseControl (..))
    import           Control.Monad.Trans.Writer   (WriterT)
    import           Data.ByteString              (ByteString)
    import qualified Data.ByteString.Char8        as B (dropWhile, intercalate, null, reverse)
    import           Data.Configurator.Types      (Config)
    import           Data.IORef                   (IORef)
    import           Data.Text                    (Text)
    import           Snap.Core                    (MonadSnap, Request (rqClientAddr), Snap, bracketSnap, getRequest, pass, writeText)
    import qualified Snap.Snaplet.Internal.Lensed as L (Lensed (..), runLensed, with, withTop)
    import qualified Snap.Snaplet.Internal.LensT  as LT (LensT, getBase, with, withTop)

    #if !MIN_VERSION_base(4,8,0)
    import           Control.Applicative          (Applicative)
    import           Data.Monoid                  (Monoid (mappend, mempty))
    #endif

    #if !MIN_VERSION_base(4,11,0)
    import           Data.Semigroup               (Semigroup(..))
    #endif

    ------------------------------------------------------------------------------

    ------------------------------------------------------------------------------
    -- | An opaque data type holding internal snaplet configuration data.  It is
    -- exported publicly because the getOpaqueConfig function in MonadSnaplet
    -- makes implementing new instances of MonadSnaplet more convenient.
    data SnapletConfig = SnapletConfig
        { SnapletConfig -> [Text]
    _scAncestry        :: [Text]
        , SnapletConfig -> FilePath
    _scFilePath        :: FilePath
        , SnapletConfig -> Maybe Text
    _scId              :: Maybe Text
        , SnapletConfig -> Text
    _scDescription     :: Text
        , SnapletConfig -> Config
    _scUserConfig      :: Config
        , SnapletConfig -> [ByteString]
    _scRouteContext    :: [ByteString]
        , SnapletConfig -> Maybe ByteString
    _scRoutePattern    :: Maybe ByteString
            -- ^ Holds the actual route pattern passed to addRoutes for the
            -- current handler.  Nothing during initialization and before route
            -- dispatech.
        , SnapletConfig -> IO (Either Text Text)
    _reloader          :: IO (Either Text Text) -- might change
            -- ^ This is the universal reload action for the top-level site.  We
            -- can't update this in place to be a reloader for each individual
            -- snaplet because individual snaplets can't be reloaded in isolation
            -- without losing effects that subsequent hooks may have had.
        }

    makeLenses ''SnapletConfig

    ------------------------------------------------------------------------------
    -- | Joins a reversed list of directories into a path.
    buildPath :: [ByteString] -> ByteString
    buildPath :: [ByteString] -> ByteString
    buildPath ps :: [ByteString]
    ps = ByteString -> [ByteString] -> ByteString
    B.intercalate "/" ([ByteString] -> ByteString) -> [ByteString] -> ByteString
    forall a b. (a -> b) -> a -> b
    $ (ByteString -> Bool) -> [ByteString] -> [ByteString]
    forall a. (a -> Bool) -> [a] -> [a]
    filter (Bool -> Bool
    not (Bool -> Bool) -> (ByteString -> Bool) -> ByteString -> Bool
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . ByteString -> Bool
    B.null) ([ByteString] -> [ByteString]) -> [ByteString] -> [ByteString]
    forall a b. (a -> b) -> a -> b
    $ [ByteString] -> [ByteString]
    forall a. [a] -> [a]
    reverse [ByteString]
    ps

    ------------------------------------------------------------------------------
    -- | Joins a reversed list of directories into a path.
    getRootURL :: SnapletConfig -> ByteString
    getRootURL :: SnapletConfig -> ByteString
    getRootURL sc :: SnapletConfig
    sc = [ByteString] -> ByteString
    buildPath ([ByteString] -> ByteString) -> [ByteString] -> ByteString
    forall a b. (a -> b) -> a -> b
    $ SnapletConfig -> [ByteString]
    _scRouteContext SnapletConfig
    sc

    ------------------------------------------------------------------------------
    -- | Snaplet's type parameter 's' here is user-defined and can be any Haskell
    -- type.  A value of type @Snaplet s@ countains a couple of things:
    --
    -- * a value of type @s@, called the \"user state\".
    --
    -- * some bookkeeping data the framework uses to plug things together, like
    --   the snaplet's configuration, the snaplet's root directory on the
    --   filesystem, the snaplet's root URL, and so on.
    data Snaplet s = Snaplet
        { Snaplet s -> SnapletConfig
    _snapletConfig   :: SnapletConfig
        , Snaplet s -> s -> IO ()
    _snapletModifier :: s -> IO ()
            -- ^ See the _reloader comment for why we have to use this to reload
            -- single snaplets in isolation.  This action won't actually run the
            -- initializer at all.  It will only modify the existing state.  It is
            -- the responsibility of the snaplet author to avoid using this in
            -- situations where it will destroy data in its state that was created
            -- by subsequent hook actions.
        , Snaplet s -> s
    _snapletValue    :: s
        }

    makeLenses ''Snaplet

    --instance Functor Snaplet where
    --  fmap f (Snaplet c r a) = Snaplet c r (f a)
    --
    --instance Foldable Snaplet where
    --  foldMap f (Snaplet _ _ a) = f a
    --
    --instance Traversable Snaplet where
    --  traverse f (Snaplet c r a) = Snaplet c r <$> f a
    --
    --instance Comonad Snaplet where
    --  extract (Snaplet _ _ a) = a
    --
    -- #if !(MIN_VERSION_comonad(3,0,0))
    -- instance Extend Snaplet where
    -- #endif
    --   extend f w@(Snaplet c r _) = Snaplet c r (f w)

    {-
    ------------------------------------------------------------------------------
    -- | A lens referencing the opaque SnapletConfig data type held inside
    -- Snaplet.
    snapletConfig :: SimpleLens (Snaplet a) SnapletConfig

    ------------------------------------------------------------------------------
    -- | A lens referencing the user-defined state type wrapped by a Snaplet.
    snapletValue :: SimpleLens (Snaplet a) a
    -}

    -- NOTE: We cannot use one of the smaller lens packages because none of them
    -- include ALens'.  We have to use ALens' because we use lenses inside f's...
    -- f (Lens a b).  That requires ImpredicativeTypes which doesn't work.  We
    -- also can't inline the type aliases because ALens' uses Pretext which is a
    -- newtype and can't be supplied outside lens in a compatible way.

    ------------------------------------------------------------------------------
    type SnapletLens s a = ALens' s (Snaplet a)

    ------------------------------------------------------------------------------
    -- | Transforms a lens of the type you get from makeLenses to an similar lens
    -- that is more suitable for internal use.
    subSnaplet :: SnapletLens a b
               -> SnapletLens (Snaplet a) b
    subSnaplet :: SnapletLens a b -> SnapletLens (Snaplet a) b
    subSnaplet l :: SnapletLens a b
    l = (a -> Pretext (->) (Snaplet b) (Snaplet b) a)
    -> Snaplet a -> Pretext (->) (Snaplet b) (Snaplet b) (Snaplet a)
    forall s. Lens' (Snaplet s) s
    snapletValue ((a -> Pretext (->) (Snaplet b) (Snaplet b) a)
     -> Snaplet a -> Pretext (->) (Snaplet b) (Snaplet b) (Snaplet a))
    -> SnapletLens a b -> SnapletLens (Snaplet a) b
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . SnapletLens a b
    l

    ------------------------------------------------------------------------------
    -- | The m type parameter used in the MonadSnaplet type signatures will
    -- usually be either Initializer or Handler, but other monads may sometimes be
    -- useful.
    --
    -- Minimal complete definition:
    --
    -- * 'withTop'', 'with'', 'getLens', and 'getOpaqueConfig'.
    --
    class MonadSnaplet m where
        -- | Runs a child snaplet action in the current snaplet's context.  If you
        -- think about snaplet lenses using a filesystem path metaphor, the lens
        -- supplied to this snaplet must be a relative path.  In other words, the
        -- lens's base state must be the same as the current snaplet.
        with :: SnapletLens v v'
                 -- ^ A relative lens identifying a snaplet
             -> m b v' a
                 -- ^ Action from the lense's snaplet
             -> m b v a
        with l :: SnapletLens v v'
    l = SnapletLens (Snaplet v) v' -> m b v' a -> m b v a
    forall (m :: * -> * -> * -> *) v v' b a.
    MonadSnaplet m =>
    SnapletLens (Snaplet v) v' -> m b v' a -> m b v a
    with' (SnapletLens v v' -> SnapletLens (Snaplet v) v'
    forall a b. SnapletLens a b -> SnapletLens (Snaplet a) b
    subSnaplet SnapletLens v v'
    l)

        -- | Like 'with' but doesn't impose the requirement that the action
        -- being run be a descendant of the current snaplet.  Using our filesystem
        -- metaphor again, the lens for this function must be an absolute
        -- path--it's base must be the same as the current base.
        withTop :: SnapletLens b v'
                    -- ^ An \"absolute\" lens identifying a snaplet
                -> m b v' a
                    -- ^ Action from the lense's snaplet
                -> m b v a
        withTop l :: SnapletLens b v'
    l = SnapletLens (Snaplet b) v' -> m b v' a -> m b v a
    forall (m :: * -> * -> * -> *) b v' a v.
    MonadSnaplet m =>
    SnapletLens (Snaplet b) v' -> m b v' a -> m b v a
    withTop' (SnapletLens b v' -> SnapletLens (Snaplet b) v'
    forall a b. SnapletLens a b -> SnapletLens (Snaplet a) b
    subSnaplet SnapletLens b v'
    l)

        -- | A variant of 'with' accepting a lens from snaplet to snaplet.  Unlike
        -- the lens used in the above 'with' function, this lens formulation has
        -- an identity, which makes it useful in certain circumstances.  The
        -- lenses generated by 'makeLenses' will not work with this function,
        -- however the lens returned by 'getLens' will.
        --
        -- @with = with' . subSnaplet@
        with' :: SnapletLens (Snaplet v) v'
              -> m b v' a -> m b v a

        -- Not providing a definition for this function in terms of withTop'
        -- allows us to avoid extra Monad type class constraints, making the type
        -- signature easier to read.
        -- with' l m = flip withTop m . (l .) =<< getLens

        -- | The absolute version of 'with''
        withTop' :: SnapletLens (Snaplet b) v'
                 -> m b v' a -> m b v a

        -- | Gets the lens for the current snaplet.
        getLens :: m b v (SnapletLens (Snaplet b) v)

        -- | Gets the current snaplet's opaque config data type.  You'll only use
        -- this function when writing MonadSnaplet instances.
        getOpaqueConfig :: m b v SnapletConfig
        -- NOTE: We can't just use a MonadState (Snaplet v) instance for this
        -- because Initializer has SnapletConfig, but doesn't have a full Snaplet.

    ------------------------------------------------------------------------------
    -- | Gets a list of the names of snaplets that are direct ancestors of the
    -- current snaplet.
    getSnapletAncestry :: (Monad (m b v), MonadSnaplet m) => m b v [Text]
    getSnapletAncestry :: m b v [Text]
    getSnapletAncestry = [Text] -> m b v [Text]
    forall (m :: * -> *) a. Monad m => a -> m a
    return ([Text] -> m b v [Text])
    -> (SnapletConfig -> [Text]) -> SnapletConfig -> m b v [Text]
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . SnapletConfig -> [Text]
    _scAncestry (SnapletConfig -> m b v [Text])
    -> m b v SnapletConfig -> m b v [Text]
    forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
    =<< m b v SnapletConfig
    forall (m :: * -> * -> * -> *) b v.
    MonadSnaplet m =>
    m b v SnapletConfig
    getOpaqueConfig

    ------------------------------------------------------------------------------
    -- | Gets the snaplet's path on the filesystem.
    getSnapletFilePath :: (Monad (m b v), MonadSnaplet m) => m b v FilePath
    getSnapletFilePath :: m b v FilePath
    getSnapletFilePath = FilePath -> m b v FilePath
    forall (m :: * -> *) a. Monad m => a -> m a
    return (FilePath -> m b v FilePath)
    -> (SnapletConfig -> FilePath) -> SnapletConfig -> m b v FilePath
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . SnapletConfig -> FilePath
    _scFilePath (SnapletConfig -> m b v FilePath)
    -> m b v SnapletConfig -> m b v FilePath
    forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
    =<< m b v SnapletConfig
    forall (m :: * -> * -> * -> *) b v.
    MonadSnaplet m =>
    m b v SnapletConfig
    getOpaqueConfig

    ------------------------------------------------------------------------------
    -- | Gets the current snaple's name.
    getSnapletName :: (Monad (m b v), MonadSnaplet m) => m b v (Maybe Text)
    getSnapletName :: m b v (Maybe Text)
    getSnapletName = Maybe Text -> m b v (Maybe Text)
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Maybe Text -> m b v (Maybe Text))
    -> (SnapletConfig -> Maybe Text)
    -> SnapletConfig
    -> m b v (Maybe Text)
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . SnapletConfig -> Maybe Text
    _scId (SnapletConfig -> m b v (Maybe Text))
    -> m b v SnapletConfig -> m b v (Maybe Text)
    forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
    =<< m b v SnapletConfig
    forall (m :: * -> * -> * -> *) b v.
    MonadSnaplet m =>
    m b v SnapletConfig
    getOpaqueConfig

    ------------------------------------------------------------------------------
    -- | Gets a human readable description of the snaplet.
    getSnapletDescription :: (Monad (m b v), MonadSnaplet m) => m b v Text
    getSnapletDescription :: m b v Text
    getSnapletDescription = Text -> m b v Text
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Text -> m b v Text)
    -> (SnapletConfig -> Text) -> SnapletConfig -> m b v Text
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . SnapletConfig -> Text
    _scDescription (SnapletConfig -> m b v Text) -> m b v SnapletConfig -> m b v Text
    forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
    =<< m b v SnapletConfig
    forall (m :: * -> * -> * -> *) b v.
    MonadSnaplet m =>
    m b v SnapletConfig
    getOpaqueConfig

    ------------------------------------------------------------------------------
    -- | Gets the config data structure for the current snaplet.
    getSnapletUserConfig :: (Monad (m b v), MonadSnaplet m) => m b v Config
    getSnapletUserConfig :: m b v Config
    getSnapletUserConfig = Config -> m b v Config
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Config -> m b v Config)
    -> (SnapletConfig -> Config) -> SnapletConfig -> m b v Config
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . SnapletConfig -> Config
    _scUserConfig (SnapletConfig -> m b v Config)
    -> m b v SnapletConfig -> m b v Config
    forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
    =<< m b v SnapletConfig
    forall (m :: * -> * -> * -> *) b v.
    MonadSnaplet m =>
    m b v SnapletConfig
    getOpaqueConfig

    ------------------------------------------------------------------------------
    -- | Gets the base URL for the current snaplet.  Directories get added to
    -- the current snaplet path by calls to 'nestSnaplet'.
    getSnapletRootURL :: (Monad (m b v), MonadSnaplet m) => m b v ByteString
    getSnapletRootURL :: m b v ByteString
    getSnapletRootURL = (SnapletConfig -> ByteString)
    -> m b v SnapletConfig -> m b v ByteString
    forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
    liftM SnapletConfig -> ByteString
    getRootURL m b v SnapletConfig
    forall (m :: * -> * -> * -> *) b v.
    MonadSnaplet m =>
    m b v SnapletConfig
    getOpaqueConfig

    ------------------------------------------------------------------------------
    -- | Constructs a url relative to the current snaplet.
    snapletURL :: (Monad (m b v), MonadSnaplet m)
               => ByteString -> m b v ByteString
    snapletURL :: ByteString -> m b v ByteString
    snapletURL suffix :: ByteString
    suffix = do
        SnapletConfig
    cfg <- m b v SnapletConfig
    forall (m :: * -> * -> * -> *) b v.
    MonadSnaplet m =>
    m b v SnapletConfig
    getOpaqueConfig
        ByteString -> m b v ByteString
    forall (m :: * -> *) a. Monad m => a -> m a
    return (ByteString -> m b v ByteString) -> ByteString -> m b v ByteString
    forall a b. (a -> b) -> a -> b
    $ [ByteString] -> ByteString
    buildPath (ByteString
    cleanSuffix ByteString -> [ByteString] -> [ByteString]
    forall a. a -> [a] -> [a]
    : SnapletConfig -> [ByteString]
    _scRouteContext SnapletConfig
    cfg)
      where
        dropSlash :: ByteString -> ByteString
    dropSlash = (Char -> Bool) -> ByteString -> ByteString
    B.dropWhile (Char -> Char -> Bool
    forall a. Eq a => a -> a -> Bool
    =='/')
        cleanSuffix :: ByteString
    cleanSuffix = ByteString -> ByteString
    B.reverse (ByteString -> ByteString) -> ByteString -> ByteString
    forall a b. (a -> b) -> a -> b
    $ ByteString -> ByteString
    dropSlash (ByteString -> ByteString) -> ByteString -> ByteString
    forall a b. (a -> b) -> a -> b
    $ ByteString -> ByteString
    B.reverse (ByteString -> ByteString) -> ByteString -> ByteString
    forall a b. (a -> b) -> a -> b
    $ ByteString -> ByteString
    dropSlash ByteString
    suffix

    ------------------------------------------------------------------------------
    -- | Snaplet infrastructure is available during runtime request processing
    -- through the Handler monad.  There aren't very many standalone functions to
    -- read about here, but this is deceptive.  The key is in the type class
    -- instances.  Handler is an instance of 'MonadSnap', which means it is the
    -- monad you will use to write all your application routes.  It also has a
    -- 'MonadSnaplet' instance, which gives you all the functionality described
    -- above.
    newtype Handler b v a =
        Handler { Handler b v a -> Lensed (Snaplet b) (Snaplet v) Snap a
    _unHandler :: L.Lensed (Snaplet b) (Snaplet v) Snap a }
      deriving ( Applicative (Handler b v)
    a -> Handler b v a
    Applicative (Handler b v) =>
    (forall a b.
     Handler b v a -> (a -> Handler b v b) -> Handler b v b)
    -> (forall a b. Handler b v a -> Handler b v b -> Handler b v b)
    -> (forall a. a -> Handler b v a)
    -> Monad (Handler b v)
    Handler b v a -> (a -> Handler b v b) -> Handler b v b
    Handler b v a -> Handler b v b -> Handler b v b
    forall a. a -> Handler b v a
    forall b v. Applicative (Handler b v)
    forall a b. Handler b v a -> Handler b v b -> Handler b v b
    forall a b. Handler b v a -> (a -> Handler b v b) -> Handler b v b
    forall b v a. a -> Handler b v a
    forall b v a b. Handler b v a -> Handler b v b -> Handler b v b
    forall b v a b.
    Handler b v a -> (a -> Handler b v b) -> Handler b v b
    forall (m :: * -> *).
    Applicative m =>
    (forall a b. m a -> (a -> m b) -> m b)
    -> (forall a b. m a -> m b -> m b)
    -> (forall a. a -> m a)
    -> Monad m
    return :: a -> Handler b v a
    $creturn :: forall b v a. a -> Handler b v a
    >> :: Handler b v a -> Handler b v b -> Handler b v b
    $c>> :: forall b v a b. Handler b v a -> Handler b v b -> Handler b v b
    >>= :: Handler b v a -> (a -> Handler b v b) -> Handler b v b
    $c>>= :: forall b v a b.
    Handler b v a -> (a -> Handler b v b) -> Handler b v b
    $cp1Monad :: forall b v. Applicative (Handler b v)
    Monad
               , a -> Handler b v b -> Handler b v a
    (a -> b) -> Handler b v a -> Handler b v b
    (forall a b. (a -> b) -> Handler b v a -> Handler b v b)
    -> (forall a b. a -> Handler b v b -> Handler b v a)
    -> Functor (Handler b v)
    forall a b. a -> Handler b v b -> Handler b v a
    forall a b. (a -> b) -> Handler b v a -> Handler b v b
    forall b v a b. a -> Handler b v b -> Handler b v a
    forall b v a b. (a -> b) -> Handler b v a -> Handler b v b
    forall (f :: * -> *).
    (forall a b. (a -> b) -> f a -> f b)
    -> (forall a b. a -> f b -> f a) -> Functor f
    <$ :: a -> Handler b v b -> Handler b v a
    $c<$ :: forall b v a b. a -> Handler b v b -> Handler b v a
    fmap :: (a -> b) -> Handler b v a -> Handler b v b
    $cfmap :: forall b v a b. (a -> b) -> Handler b v a -> Handler b v b
    Functor
               , Functor (Handler b v)
    a -> Handler b v a
    Functor (Handler b v) =>
    (forall a. a -> Handler b v a)
    -> (forall a b.
        Handler b v (a -> b) -> Handler b v a -> Handler b v b)
    -> (forall a b c.
        (a -> b -> c) -> Handler b v a -> Handler b v b -> Handler b v c)
    -> (forall a b. Handler b v a -> Handler b v b -> Handler b v b)
    -> (forall a b. Handler b v a -> Handler b v b -> Handler b v a)
    -> Applicative (Handler b v)
    Handler b v a -> Handler b v b -> Handler b v b
    Handler b v a -> Handler b v b -> Handler b v a
    Handler b v (a -> b) -> Handler b v a -> Handler b v b
    (a -> b -> c) -> Handler b v a -> Handler b v b -> Handler b v c
    forall a. a -> Handler b v a
    forall b v. Functor (Handler b v)
    forall a b. Handler b v a -> Handler b v b -> Handler b v a
    forall a b. Handler b v a -> Handler b v b -> Handler b v b
    forall a b. Handler b v (a -> b) -> Handler b v a -> Handler b v b
    forall b v a. a -> Handler b v a
    forall a b c.
    (a -> b -> c) -> Handler b v a -> Handler b v b -> Handler b v c
    forall b v a b. Handler b v a -> Handler b v b -> Handler b v a
    forall b v a b. Handler b v a -> Handler b v b -> Handler b v b
    forall b v a b.
    Handler b v (a -> b) -> Handler b v a -> Handler b v b
    forall b v a b c.
    (a -> b -> c) -> Handler b v a -> Handler b v b -> Handler b v c
    forall (f :: * -> *).
    Functor f =>
    (forall a. a -> f a)
    -> (forall a b. f (a -> b) -> f a -> f b)
    -> (forall a b c. (a -> b -> c) -> f a -> f b -> f c)
    -> (forall a b. f a -> f b -> f b)
    -> (forall a b. f a -> f b -> f a)
    -> Applicative f
    <* :: Handler b v a -> Handler b v b -> Handler b v a
    $c<* :: forall b v a b. Handler b v a -> Handler b v b -> Handler b v a
    *> :: Handler b v a -> Handler b v b -> Handler b v b
    $c*> :: forall b v a b. Handler b v a -> Handler b v b -> Handler b v b
    liftA2 :: (a -> b -> c) -> Handler b v a -> Handler b v b -> Handler b v c
    $cliftA2 :: forall b v a b c.
    (a -> b -> c) -> Handler b v a -> Handler b v b -> Handler b v c
    <*> :: Handler b v (a -> b) -> Handler b v a -> Handler b v b
    $c<*> :: forall b v a b.
    Handler b v (a -> b) -> Handler b v a -> Handler b v b
    pure :: a -> Handler b v a
    $cpure :: forall b v a. a -> Handler b v a
    $cp1Applicative :: forall b v. Functor (Handler b v)
    Applicative
               , Monad (Handler b v)
    Monad (Handler b v) =>
    (forall a. FilePath -> Handler b v a) -> MonadFail (Handler b v)
    FilePath -> Handler b v a
    forall a. FilePath -> Handler b v a
    forall b v. Monad (Handler b v)
    forall b v a. FilePath -> Handler b v a
    forall (m :: * -> *).
    Monad m =>
    (forall a. FilePath -> m a) -> MonadFail m
    fail :: FilePath -> Handler b v a
    $cfail :: forall b v a. FilePath -> Handler b v a
    $cp1MonadFail :: forall b v. Monad (Handler b v)
    MonadFail
               , Monad (Handler b v)
    Monad (Handler b v) =>
    (forall a. IO a -> Handler b v a) -> MonadIO (Handler b v)
    IO a -> Handler b v a
    forall a. IO a -> Handler b v a
    forall b v. Monad (Handler b v)
    forall b v a. IO a -> Handler b v a
    forall (m :: * -> *).
    Monad m =>
    (forall a. IO a -> m a) -> MonadIO m
    liftIO :: IO a -> Handler b v a
    $cliftIO :: forall b v a. IO a -> Handler b v a
    $cp1MonadIO :: forall b v. Monad (Handler b v)
    MonadIO
               , Monad (Handler b v)
    Alternative (Handler b v)
    Handler b v a
    (Alternative (Handler b v), Monad (Handler b v)) =>
    (forall a. Handler b v a)
    -> (forall a. Handler b v a -> Handler b v a -> Handler b v a)
    -> MonadPlus (Handler b v)
    Handler b v a -> Handler b v a -> Handler b v a
    forall a. Handler b v a
    forall a. Handler b v a -> Handler b v a -> Handler b v a
    forall b v. Monad (Handler b v)
    forall b v. Alternative (Handler b v)
    forall b v a. Handler b v a
    forall b v a. Handler b v a -> Handler b v a -> Handler b v a
    forall (m :: * -> *).
    (Alternative m, Monad m) =>
    (forall a. m a) -> (forall a. m a -> m a -> m a) -> MonadPlus m
    mplus :: Handler b v a -> Handler b v a -> Handler b v a
    $cmplus :: forall b v a. Handler b v a -> Handler b v a -> Handler b v a
    mzero :: Handler b v a
    $cmzero :: forall b v a. Handler b v a
    $cp2MonadPlus :: forall b v. Monad (Handler b v)
    $cp1MonadPlus :: forall b v. Alternative (Handler b v)
    MonadPlus
               , Applicative (Handler b v)
    Handler b v a
    Applicative (Handler b v) =>
    (forall a. Handler b v a)
    -> (forall a. Handler b v a -> Handler b v a -> Handler b v a)
    -> (forall a. Handler b v a -> Handler b v [a])
    -> (forall a. Handler b v a -> Handler b v [a])
    -> Alternative (Handler b v)
    Handler b v a -> Handler b v a -> Handler b v a
    Handler b v a -> Handler b v [a]
    Handler b v a -> Handler b v [a]
    forall a. Handler b v a
    forall a. Handler b v a -> Handler b v [a]
    forall a. Handler b v a -> Handler b v a -> Handler b v a
    forall b v. Applicative (Handler b v)
    forall b v a. Handler b v a
    forall b v a. Handler b v a -> Handler b v [a]
    forall b v a. Handler b v a -> Handler b v a -> Handler b v a
    forall (f :: * -> *).
    Applicative f =>
    (forall a. f a)
    -> (forall a. f a -> f a -> f a)
    -> (forall a. f a -> f [a])
    -> (forall a. f a -> f [a])
    -> Alternative f
    many :: Handler b v a -> Handler b v [a]
    $cmany :: forall b v a. Handler b v a -> Handler b v [a]
    some :: Handler b v a -> Handler b v [a]
    $csome :: forall b v a. Handler b v a -> Handler b v [a]
    <|> :: Handler b v a -> Handler b v a -> Handler b v a
    $c<|> :: forall b v a. Handler b v a -> Handler b v a -> Handler b v a
    empty :: Handler b v a
    $cempty :: forall b v a. Handler b v a
    $cp1Alternative :: forall b v. Applicative (Handler b v)
    Alternative
               , Monad (Handler b v)
    Functor (Handler b v)
    Applicative (Handler b v)
    Alternative (Handler b v)
    MonadPlus (Handler b v)
    MonadBaseControl IO (Handler b v)
    MonadIO (Handler b v)
    (Monad (Handler b v), MonadIO (Handler b v),
     MonadBaseControl IO (Handler b v), MonadPlus (Handler b v),
     Functor (Handler b v), Applicative (Handler b v),
     Alternative (Handler b v)) =>
    (forall a. Snap a -> Handler b v a) -> MonadSnap (Handler b v)
    Snap a -> Handler b v a
    forall a. Snap a -> Handler b v a
    forall b v. Monad (Handler b v)
    forall b v. Functor (Handler b v)
    forall b v. Applicative (Handler b v)
    forall b v. Alternative (Handler b v)
    forall b v. MonadPlus (Handler b v)
    forall b v. MonadBaseControl IO (Handler b v)
    forall b v. MonadIO (Handler b v)
    forall b v a. Snap a -> Handler b v a
    forall (m :: * -> *).
    (Monad m, MonadIO m, MonadBaseControl IO m, MonadPlus m, Functor m,
     Applicative m, Alternative m) =>
    (forall a. Snap a -> m a) -> MonadSnap m
    liftSnap :: Snap a -> Handler b v a
    $cliftSnap :: forall b v a. Snap a -> Handler b v a
    $cp7MonadSnap :: forall b v. Alternative (Handler b v)
    $cp6MonadSnap :: forall b v. Applicative (Handler b v)
    $cp5MonadSnap :: forall b v. Functor (Handler b v)
    $cp4MonadSnap :: forall b v. MonadPlus (Handler b v)
    $cp3MonadSnap :: forall b v. MonadBaseControl IO (Handler b v)
    $cp2MonadSnap :: forall b v. MonadIO (Handler b v)
    $cp1MonadSnap :: forall b v. Monad (Handler b v)
    MonadSnap)

    ------------------------------------------------------------------------------
    instance MonadBase IO (Handler b v) where
        liftBase :: IO α -> Handler b v α
    liftBase = IO α -> Handler b v α
    forall (m :: * -> *) a. MonadIO m => IO a -> m a
    liftIO

    ------------------------------------------------------------------------------
    newtype StMHandler b v a = StMHandler {
          StMHandler b v a -> StM (Lensed (Snaplet b) (Snaplet v) Snap) a
    unStMHandler :: StM (L.Lensed (Snaplet b) (Snaplet v) Snap) a
        }

    instance MonadBaseControl IO (Handler b v) where
        type StM (Handler b v) a = StMHandler b v a
        liftBaseWith :: (RunInBase (Handler b v) IO -> IO a) -> Handler b v a
    liftBaseWith f :: RunInBase (Handler b v) IO -> IO a
    f = Lensed (Snaplet b) (Snaplet v) Snap a -> Handler b v a
    forall b v a.
    Lensed (Snaplet b) (Snaplet v) Snap a -> Handler b v a
    Handler
                           (Lensed (Snaplet b) (Snaplet v) Snap a -> Handler b v a)
    -> Lensed (Snaplet b) (Snaplet v) Snap a -> Handler b v a
    forall a b. (a -> b) -> a -> b
    $ (RunInBase (Lensed (Snaplet b) (Snaplet v) Snap) IO -> IO a)
    -> Lensed (Snaplet b) (Snaplet v) Snap a
    forall (b :: * -> *) (m :: * -> *) a.
    MonadBaseControl b m =>
    (RunInBase m b -> b a) -> m a
    liftBaseWith
                           ((RunInBase (Lensed (Snaplet b) (Snaplet v) Snap) IO -> IO a)
     -> Lensed (Snaplet b) (Snaplet v) Snap a)
    -> (RunInBase (Lensed (Snaplet b) (Snaplet v) Snap) IO -> IO a)
    -> Lensed (Snaplet b) (Snaplet v) Snap a
    forall a b. (a -> b) -> a -> b
    $ \g' :: RunInBase (Lensed (Snaplet b) (Snaplet v) Snap) IO
    g' -> RunInBase (Handler b v) IO -> IO a
    f
                           (RunInBase (Handler b v) IO -> IO a)
    -> RunInBase (Handler b v) IO -> IO a
    forall a b. (a -> b) -> a -> b
    $ \m :: Handler b v a
    m -> (StSnap (a, Snaplet v, Snaplet b) -> StMHandler b v a)
    -> IO (StSnap (a, Snaplet v, Snaplet b)) -> IO (StMHandler b v a)
    forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
    liftM StSnap (a, Snaplet v, Snaplet b) -> StMHandler b v a
    forall b v a.
    StM (Lensed (Snaplet b) (Snaplet v) Snap) a -> StMHandler b v a
    StMHandler
                           (IO (StSnap (a, Snaplet v, Snaplet b)) -> IO (StM (Handler b v) a))
    -> IO (StSnap (a, Snaplet v, Snaplet b))
    -> IO (StM (Handler b v) a)
    forall a b. (a -> b) -> a -> b
    $ Lensed (Snaplet b) (Snaplet v) Snap a
    -> IO (StSnap (a, Snaplet v, Snaplet b))
    RunInBase (Lensed (Snaplet b) (Snaplet v) Snap) IO
    g' (Lensed (Snaplet b) (Snaplet v) Snap a
     -> IO (StSnap (a, Snaplet v, Snaplet b)))
    -> Lensed (Snaplet b) (Snaplet v) Snap a
    -> IO (StSnap (a, Snaplet v, Snaplet b))
    forall a b. (a -> b) -> a -> b
    $ Handler b v a -> Lensed (Snaplet b) (Snaplet v) Snap a
    forall b v a.
    Handler b v a -> Lensed (Snaplet b) (Snaplet v) Snap a
    _unHandler Handler b v a
    m
        restoreM :: StM (Handler b v) a -> Handler b v a
    restoreM = Lensed (Snaplet b) (Snaplet v) Snap a -> Handler b v a
    forall b v a.
    Lensed (Snaplet b) (Snaplet v) Snap a -> Handler b v a
    Handler (Lensed (Snaplet b) (Snaplet v) Snap a -> Handler b v a)
    -> (StMHandler b v a -> Lensed (Snaplet b) (Snaplet v) Snap a)
    -> StMHandler b v a
    -> Handler b v a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . StSnap (a, Snaplet v, Snaplet b)
    -> Lensed (Snaplet b) (Snaplet v) Snap a
    forall (b :: * -> *) (m :: * -> *) a.
    MonadBaseControl b m =>
    StM m a -> m a
    restoreM (StSnap (a, Snaplet v, Snaplet b)
     -> Lensed (Snaplet b) (Snaplet v) Snap a)
    -> (StMHandler b v a -> StSnap (a, Snaplet v, Snaplet b))
    -> StMHandler b v a
    -> Lensed (Snaplet b) (Snaplet v) Snap a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . StMHandler b v a -> StSnap (a, Snaplet v, Snaplet b)
    forall b v a.
    StMHandler b v a -> StM (Lensed (Snaplet b) (Snaplet v) Snap) a
    unStMHandler

    ------------------------------------------------------------------------------
    -- | Gets the @Snaplet v@ from the current snaplet's state.
    getSnapletState :: Handler b v (Snaplet v)
    getSnapletState :: Handler b v (Snaplet v)
    getSnapletState = Lensed (Snaplet b) (Snaplet v) Snap (Snaplet v)
    -> Handler b v (Snaplet v)
    forall b v a.
    Lensed (Snaplet b) (Snaplet v) Snap a -> Handler b v a
    Handler Lensed (Snaplet b) (Snaplet v) Snap (Snaplet v)
    forall s (m :: * -> *). MonadState s m => m s
    get

    ------------------------------------------------------------------------------
    -- | Puts a new @Snaplet v@ in the current snaplet's state.
    putSnapletState :: Snaplet v -> Handler b v ()
    putSnapletState :: Snaplet v -> Handler b v ()
    putSnapletState = Lensed (Snaplet b) (Snaplet v) Snap () -> Handler b v ()
    forall b v a.
    Lensed (Snaplet b) (Snaplet v) Snap a -> Handler b v a
    Handler (Lensed (Snaplet b) (Snaplet v) Snap () -> Handler b v ())
    -> (Snaplet v -> Lensed (Snaplet b) (Snaplet v) Snap ())
    -> Snaplet v
    -> Handler b v ()
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Snaplet v -> Lensed (Snaplet b) (Snaplet v) Snap ()
    forall s (m :: * -> *). MonadState s m => s -> m ()
    put

    ------------------------------------------------------------------------------
    -- | Modifies the @Snaplet v@ in the current snaplet's state.
    modifySnapletState :: (Snaplet v -> Snaplet v) -> Handler b v ()
    modifySnapletState :: (Snaplet v -> Snaplet v) -> Handler b v ()
    modifySnapletState f :: Snaplet v -> Snaplet v
    f = do
        Snaplet v
    s <- Handler b v (Snaplet v)
    forall b v. Handler b v (Snaplet v)
    getSnapletState
        Snaplet v -> Handler b v ()
    forall v b. Snaplet v -> Handler b v ()
    putSnapletState (Snaplet v -> Snaplet v
    f Snaplet v
    s)

    ------------------------------------------------------------------------------
    -- | Gets the @Snaplet v@ from the current snaplet's state and applies a
    -- function to it.
    getsSnapletState :: (Snaplet v -> b) -> Handler b1 v b
    getsSnapletState :: (Snaplet v -> b) -> Handler b1 v b
    getsSnapletState f :: Snaplet v -> b
    f = do
        Snaplet v
    s <- Handler b1 v (Snaplet v)
    forall b v. Handler b v (Snaplet v)
    getSnapletState
        b -> Handler b1 v b
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Snaplet v -> b
    f Snaplet v
    s)

    ------------------------------------------------------------------------------
    -- | Lets you access the current snaplet's state through the 'MonadState'
    -- interface.
    instance MonadState v (Handler b v) where
        get :: Handler b v v
    get = (Snaplet v -> v) -> Handler b v v
    forall v b b1. (Snaplet v -> b) -> Handler b1 v b
    getsSnapletState Snaplet v -> v
    forall s. Snaplet s -> s
    _snapletValue
        put :: v -> Handler b v ()
    put v :: v
    v = (Snaplet v -> Snaplet v) -> Handler b v ()
    forall v b. (Snaplet v -> Snaplet v) -> Handler b v ()
    modifySnapletState (ASetter (Snaplet v) (Snaplet v) v v -> v -> Snaplet v -> Snaplet v
    forall s t a b. ASetter s t a b -> b -> s -> t
    set ASetter (Snaplet v) (Snaplet v) v v
    forall s. Lens' (Snaplet s) s
    snapletValue v
    v)

    ------------------------------------------------------------------------------
    -- | Lets you access the current snaplet's state through the 'MonadReader'
    -- interface.
    instance MonadReader v (Handler b v) where
        ask :: Handler b v v
    ask = (Snaplet v -> v) -> Handler b v v
    forall v b b1. (Snaplet v -> b) -> Handler b1 v b
    getsSnapletState Snaplet v -> v
    forall s. Snaplet s -> s
    _snapletValue
        local :: (v -> v) -> Handler b v a -> Handler b v a
    local f :: v -> v
    f m :: Handler b v a
    m = do
            v
    cur <- Handler b v v
    forall r (m :: * -> *). MonadReader r m => m r
    ask
            v -> Handler b v ()
    forall s (m :: * -> *). MonadState s m => s -> m ()
    put (v -> v
    f v
    cur)
            a
    res <- Handler b v a
    m
            v -> Handler b v ()
    forall s (m :: * -> *). MonadState s m => s -> m ()
    put v
    cur
            a -> Handler b v a
    forall (m :: * -> *) a. Monad m => a -> m a
    return a
    res

    ------------------------------------------------------------------------------
    instance MonadSnaplet Handler where
        getLens :: Handler b v (SnapletLens (Snaplet b) v)
    getLens = Lensed (Snaplet b) (Snaplet v) Snap (SnapletLens (Snaplet b) v)
    -> Handler b v (SnapletLens (Snaplet b) v)
    forall b v a.
    Lensed (Snaplet b) (Snaplet v) Snap a -> Handler b v a
    Handler Lensed (Snaplet b) (Snaplet v) Snap (SnapletLens (Snaplet b) v)
    forall r (m :: * -> *). MonadReader r m => m r
    ask
        with' :: SnapletLens (Snaplet v) v' -> Handler b v' a -> Handler b v a
    with' !SnapletLens (Snaplet v) v'
    l (Handler !Lensed (Snaplet b) (Snaplet v') Snap a
    m) = Lensed (Snaplet b) (Snaplet v) Snap a -> Handler b v a
    forall b v a.
    Lensed (Snaplet b) (Snaplet v) Snap a -> Handler b v a
    Handler (Lensed (Snaplet b) (Snaplet v) Snap a -> Handler b v a)
    -> Lensed (Snaplet b) (Snaplet v) Snap a -> Handler b v a
    forall a b. (a -> b) -> a -> b
    $ SnapletLens (Snaplet v) v'
    -> Lensed (Snaplet b) (Snaplet v') Snap a
    -> Lensed (Snaplet b) (Snaplet v) Snap a
    forall (m :: * -> *) v v' b a.
    Monad m =>
    ALens' v v' -> Lensed b v' m a -> Lensed b v m a
    L.with SnapletLens (Snaplet v) v'
    l Lensed (Snaplet b) (Snaplet v') Snap a
    m
        withTop' :: SnapletLens (Snaplet b) v' -> Handler b v' a -> Handler b v a
    withTop' !SnapletLens (Snaplet b) v'
    l (Handler m :: Lensed (Snaplet b) (Snaplet v') Snap a
    m) = Lensed (Snaplet b) (Snaplet v) Snap a -> Handler b v a
    forall b v a.
    Lensed (Snaplet b) (Snaplet v) Snap a -> Handler b v a
    Handler (Lensed (Snaplet b) (Snaplet v) Snap a -> Handler b v a)
    -> Lensed (Snaplet b) (Snaplet v) Snap a -> Handler b v a
    forall a b. (a -> b) -> a -> b
    $ SnapletLens (Snaplet b) v'
    -> Lensed (Snaplet b) (Snaplet v') Snap a
    -> Lensed (Snaplet b) (Snaplet v) Snap a
    forall (m :: * -> *) b v' a v.
    Monad m =>
    ALens' b v' -> Lensed b v' m a -> Lensed b v m a
    L.withTop SnapletLens (Snaplet b) v'
    l Lensed (Snaplet b) (Snaplet v') Snap a
    m
        getOpaqueConfig :: Handler b v SnapletConfig
    getOpaqueConfig = Lensed (Snaplet b) (Snaplet v) Snap SnapletConfig
    -> Handler b v SnapletConfig
    forall b v a.
    Lensed (Snaplet b) (Snaplet v) Snap a -> Handler b v a
    Handler (Lensed (Snaplet b) (Snaplet v) Snap SnapletConfig
     -> Handler b v SnapletConfig)
    -> Lensed (Snaplet b) (Snaplet v) Snap SnapletConfig
    -> Handler b v SnapletConfig
    forall a b. (a -> b) -> a -> b
    $ (Snaplet v -> SnapletConfig)
    -> Lensed (Snaplet b) (Snaplet v) Snap SnapletConfig
    forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
    gets Snaplet v -> SnapletConfig
    forall s. Snaplet s -> SnapletConfig
    _snapletConfig

    ------------------------------------------------------------------------------
    -- | Like 'runBase', but it doesn't require an MVar to be executed.
    runPureBase :: Handler b b a -> Snaplet b -> Snap a
    runPureBase :: Handler b b a -> Snaplet b -> Snap a
    runPureBase (Handler m :: Lensed (Snaplet b) (Snaplet b) Snap a
    m) b :: Snaplet b
    b = do
            (!a
    a, _) <- Lensed (Snaplet b) (Snaplet b) Snap a
    -> ALens' (Snaplet b) (Snaplet b)
    -> Snaplet b
    -> Snap (a, Snaplet b)
    forall (m :: * -> *) t1 b t.
    Monad m =>
    Lensed t1 b m t -> ALens' t1 b -> t1 -> m (t, t1)
    L.runLensed Lensed (Snaplet b) (Snaplet b) Snap a
    m ALens' (Snaplet b) (Snaplet b)
    forall a. a -> a
    id Snaplet b
    b
            a -> Snap a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (a -> Snap a) -> a -> Snap a
    forall a b. (a -> b) -> a -> b
    $! a
    a

    ------------------------------------------------------------------------------
    -- | Gets the route pattern that matched for the handler.  This lets you find
    -- out exactly which of the strings you used in addRoutes matched.
    getRoutePattern :: Handler b v (Maybe ByteString)
    getRoutePattern :: Handler b v (Maybe ByteString)
    getRoutePattern =
        SnapletLens (Snaplet b) b
    -> Handler b b (Maybe ByteString) -> Handler b v (Maybe ByteString)
    forall (m :: * -> * -> * -> *) b v' a v.
    MonadSnaplet m =>
    SnapletLens (Snaplet b) v' -> m b v' a -> m b v a
    withTop' SnapletLens (Snaplet b) b
    forall a. a -> a
    id (Handler b b (Maybe ByteString) -> Handler b v (Maybe ByteString))
    -> Handler b b (Maybe ByteString) -> Handler b v (Maybe ByteString)
    forall a b. (a -> b) -> a -> b
    $ (SnapletConfig -> Maybe ByteString)
    -> Handler b b SnapletConfig -> Handler b b (Maybe ByteString)
    forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
    liftM SnapletConfig -> Maybe ByteString
    _scRoutePattern Handler b b SnapletConfig
    forall (m :: * -> * -> * -> *) b v.
    MonadSnaplet m =>
    m b v SnapletConfig
    getOpaqueConfig

    ------------------------------------------------------------------------------
    -- | Sets the route pattern that matched for the handler.  Use this when to
    -- override the default pattern which is the key to the alist passed to
    -- addRoutes.
    setRoutePattern :: ByteString -> Handler b v ()
    setRoutePattern :: ByteString -> Handler b v ()
    setRoutePattern p :: ByteString
    p = SnapletLens (Snaplet b) b -> Handler b b () -> Handler b v ()
    forall (m :: * -> * -> * -> *) b v' a v.
    MonadSnaplet m =>
    SnapletLens (Snaplet b) v' -> m b v' a -> m b v a
    withTop' SnapletLens (Snaplet b) b
    forall a. a -> a
    id (Handler b b () -> Handler b v ())
    -> Handler b b () -> Handler b v ()
    forall a b. (a -> b) -> a -> b
    $
        (Snaplet b -> Snaplet b) -> Handler b b ()
    forall v b. (Snaplet v -> Snaplet v) -> Handler b v ()
    modifySnapletState (ASetter
      (Snaplet b) (Snaplet b) (Maybe ByteString) (Maybe ByteString)
    -> Maybe ByteString -> Snaplet b -> Snaplet b
    forall s t a b. ASetter s t a b -> b -> s -> t
    set ((SnapletConfig -> Identity SnapletConfig)
    -> Snaplet b -> Identity (Snaplet b)
    forall s. Lens' (Snaplet s) SnapletConfig
    snapletConfig ((SnapletConfig -> Identity SnapletConfig)
     -> Snaplet b -> Identity (Snaplet b))
    -> ((Maybe ByteString -> Identity (Maybe ByteString))
        -> SnapletConfig -> Identity SnapletConfig)
    -> ASetter
         (Snaplet b) (Snaplet b) (Maybe ByteString) (Maybe ByteString)
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Maybe ByteString -> Identity (Maybe ByteString))
    -> SnapletConfig -> Identity SnapletConfig
    Lens' SnapletConfig (Maybe ByteString)
    scRoutePattern) (ByteString -> Maybe ByteString
    forall a. a -> Maybe a
    Just ByteString
    p))

    ------------------------------------------------------------------------------
    -- | Check whether the request comes from localhost.
    isLocalhost :: MonadSnap m => m Bool
    isLocalhost :: m Bool
    isLocalhost = do
        ByteString
    rip <- (Request -> ByteString) -> m Request -> m ByteString
    forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
    liftM Request -> ByteString
    rqClientAddr m Request
    forall (m :: * -> *). MonadSnap m => m Request
    getRequest
        Bool -> m Bool
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Bool -> m Bool) -> Bool -> m Bool
    forall a b. (a -> b) -> a -> b
    $ ByteString -> [ByteString] -> Bool
    forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
    elem ByteString
    rip [ "127.0.0.1"
                          , "localhost"
                          , "::1" ]

    ------------------------------------------------------------------------------
    -- | Pass if the request is not coming from localhost.
    failIfNotLocal :: MonadSnap m => m b -> m b
    failIfNotLocal :: m b -> m b
    failIfNotLocal m :: m b
    m = do
        Bool
    isLocal <- m Bool
    forall (m :: * -> *). MonadSnap m => m Bool
    isLocalhost
        if Bool
    isLocal then m b
    m else m b
    forall (m :: * -> *) a. MonadSnap m => m a
    pass

    ------------------------------------------------------------------------------
    -- | Handler that reloads the site.
    reloadSite :: Handler b v ()
    reloadSite :: Handler b v ()
    reloadSite = Handler b v () -> Handler b v ()
    forall (m :: * -> *) b. MonadSnap m => m b -> m b
    failIfNotLocal (Handler b v () -> Handler b v ())
    -> Handler b v () -> Handler b v ()
    forall a b. (a -> b) -> a -> b
    $ do
        SnapletConfig
    cfg <- Handler b v SnapletConfig
    forall (m :: * -> * -> * -> *) b v.
    MonadSnaplet m =>
    m b v SnapletConfig
    getOpaqueConfig
        !Either Text Text
    res <- IO (Either Text Text) -> Handler b v (Either Text Text)
    forall (m :: * -> *) a. MonadIO m => IO a -> m a
    liftIO (IO (Either Text Text) -> Handler b v (Either Text Text))
    -> IO (Either Text Text) -> Handler b v (Either Text Text)
    forall a b. (a -> b) -> a -> b
    $ SnapletConfig -> IO (Either Text Text)
    _reloader SnapletConfig
    cfg
        (Text -> Handler b v ())
    -> (Text -> Handler b v ()) -> Either Text Text -> Handler b v ()
    forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
    either Text -> Handler b v ()
    forall (m :: * -> *). MonadSnap m => Text -> m ()
    bad Text -> Handler b v ()
    forall (m :: * -> *). MonadSnap m => Text -> m ()
    good Either Text Text
    res
      where
        bad :: Text -> m ()
    bad msg :: Text
    msg = do
            Text -> m ()
    forall (m :: * -> *). MonadSnap m => Text -> m ()
    writeText (Text -> m ()) -> Text -> m ()
    forall a b. (a -> b) -> a -> b
    $ "Error reloading site!\n\n"
            Text -> m ()
    forall (m :: * -> *). MonadSnap m => Text -> m ()
    writeText Text
    msg
        good :: Text -> m ()
    good msg :: Text
    msg = do
            Text -> m ()
    forall (m :: * -> *). MonadSnap m => Text -> m ()
    writeText Text
    msg
            Text -> m ()
    forall (m :: * -> *). MonadSnap m => Text -> m ()
    writeText (Text -> m ()) -> Text -> m ()
    forall a b. (a -> b) -> a -> b
    $ "Site successfully reloaded.\n"

    ------------------------------------------------------------------------------
    -- | This function brackets a Handler action in resource acquisition and
    -- release.  Like 'bracketSnap',  this is provided because MonadCatchIO's
    -- 'bracket' function doesn't work properly in the case of a short-circuit
    -- return from the action being bracketed.
    --
    -- In order to prevent confusion regarding the effects of the
    -- aquisition and release actions on the Handler state, this function
    -- doesn't accept Handler actions for the acquire or release actions.
    --
    -- This function will run the release action in all cases where the
    -- acquire action succeeded.  This includes the following behaviors
    -- from the bracketed Snap action.
    --
    -- 1. Normal completion
    --
    -- 2. Short-circuit completion, either from calling 'fail' or 'finishWith'
    --
    -- 3. An exception being thrown.
    bracketHandler :: IO a -> (a -> IO x) -> (a -> Handler b v c) -> Handler b v c
    bracketHandler :: IO a -> (a -> IO x) -> (a -> Handler b v c) -> Handler b v c
    bracketHandler begin :: IO a
    begin end :: a -> IO x
    end f :: a -> Handler b v c
    f = Lensed (Snaplet b) (Snaplet v) Snap c -> Handler b v c
    forall b v a.
    Lensed (Snaplet b) (Snaplet v) Snap a -> Handler b v a
    Handler (Lensed (Snaplet b) (Snaplet v) Snap c -> Handler b v c)
    -> ((ALens' (Snaplet b) (Snaplet v)
         -> Snaplet v -> Snaplet b -> Snap (c, Snaplet v, Snaplet b))
        -> Lensed (Snaplet b) (Snaplet v) Snap c)
    -> (ALens' (Snaplet b) (Snaplet v)
        -> Snaplet v -> Snaplet b -> Snap (c, Snaplet v, Snaplet b))
    -> Handler b v c
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (ALens' (Snaplet b) (Snaplet v)
     -> Snaplet v -> Snaplet b -> Snap (c, Snaplet v, Snaplet b))
    -> Lensed (Snaplet b) (Snaplet v) Snap c
    forall b v (m :: * -> *) a.
    (ALens' b v -> v -> b -> m (a, v, b)) -> Lensed b v m a
    L.Lensed ((ALens' (Snaplet b) (Snaplet v)
      -> Snaplet v -> Snaplet b -> Snap (c, Snaplet v, Snaplet b))
     -> Handler b v c)
    -> (ALens' (Snaplet b) (Snaplet v)
        -> Snaplet v -> Snaplet b -> Snap (c, Snaplet v, Snaplet b))
    -> Handler b v c
    forall a b. (a -> b) -> a -> b
    $ \l :: ALens' (Snaplet b) (Snaplet v)
    l v :: Snaplet v
    v b :: Snaplet b
    b -> do
        IO a
    -> (a -> IO x)
    -> (a -> Snap (c, Snaplet v, Snaplet b))
    -> Snap (c, Snaplet v, Snaplet b)
    forall a b c. IO a -> (a -> IO b) -> (a -> Snap c) -> Snap c
    bracketSnap IO a
    begin a -> IO x
    end ((a -> Snap (c, Snaplet v, Snaplet b))
     -> Snap (c, Snaplet v, Snaplet b))
    -> (a -> Snap (c, Snaplet v, Snaplet b))
    -> Snap (c, Snaplet v, Snaplet b)
    forall a b. (a -> b) -> a -> b
    $ \a :: a
    a -> case a -> Handler b v c
    f a
    a of Handler m :: Lensed (Snaplet b) (Snaplet v) Snap c
    m -> Lensed (Snaplet b) (Snaplet v) Snap c
    -> ALens' (Snaplet b) (Snaplet v)
    -> Snaplet v
    -> Snaplet b
    -> Snap (c, Snaplet v, Snaplet b)
    forall b v (m :: * -> *) a.
    Lensed b v m a -> ALens' b v -> v -> b -> m (a, v, b)
    L.unlensed Lensed (Snaplet b) (Snaplet v) Snap c
    m ALens' (Snaplet b) (Snaplet v)
    l Snaplet v
    v Snaplet b
    b

    ------------------------------------------------------------------------------
    -- | Information about a partially constructed initializer.  Used to
    -- automatically aggregate handlers and cleanup actions.
    data InitializerState b = InitializerState
        { InitializerState b -> Bool
    _isTopLevel      :: Bool
        , InitializerState b -> IORef (IO ())
    _cleanup         :: IORef (IO ())
        , InitializerState b -> [(ByteString, Handler b b ())]
    _handlers        :: [(ByteString, Handler b b ())]
            -- ^ Handler routes built up and passed to route.
        , InitializerState b -> Handler b b () -> Handler b b ()
    _hFilter         :: Handler b b () -> Handler b b ()
            -- ^ Generic filtering of handlers
        , InitializerState b -> SnapletConfig
    _curConfig       :: SnapletConfig
            -- ^ This snaplet config is the incrementally built config for
            -- whatever snaplet is currently being constructed.
        , InitializerState b -> IORef Text
    _initMessages    :: IORef Text
        , InitializerState b -> FilePath
    _environment     :: String
        , InitializerState b -> (Snaplet b -> Snaplet b) -> IO ()
    masterReloader   :: (Snaplet b -> Snaplet b) -> IO ()
            -- ^ We can't just hae a simple MVar here because MVars can't be
            -- chrooted.
        }

    ------------------------------------------------------------------------------
    -- | Wrapper around IO actions that modify state elements created during
    -- initialization.
    newtype Hook a = Hook (Snaplet a -> IO (Either Text (Snaplet a)))

    instance Semigroup (Hook a) where
        Hook a :: Snaplet a -> IO (Either Text (Snaplet a))
    a <> :: Hook a -> Hook a -> Hook a
    <> Hook b :: Snaplet a -> IO (Either Text (Snaplet a))
    b = (Snaplet a -> IO (Either Text (Snaplet a))) -> Hook a
    forall a. (Snaplet a -> IO (Either Text (Snaplet a))) -> Hook a
    Hook ((Snaplet a -> IO (Either Text (Snaplet a))) -> Hook a)
    -> (Snaplet a -> IO (Either Text (Snaplet a))) -> Hook a
    forall a b. (a -> b) -> a -> b
    $ \s :: Snaplet a
    s -> do
          Either Text (Snaplet a)
    ea <- Snaplet a -> IO (Either Text (Snaplet a))
    a Snaplet a
    s
          case Either Text (Snaplet a)
    ea of
            Left e :: Text
    e -> Either Text (Snaplet a) -> IO (Either Text (Snaplet a))
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Either Text (Snaplet a) -> IO (Either Text (Snaplet a)))
    -> Either Text (Snaplet a) -> IO (Either Text (Snaplet a))
    forall a b. (a -> b) -> a -> b
    $ Text -> Either Text (Snaplet a)
    forall a b. a -> Either a b
    Left Text
    e
            Right ares :: Snaplet a
    ares -> do
              Either Text (Snaplet a)
    eb <- Snaplet a -> IO (Either Text (Snaplet a))
    b Snaplet a
    ares
              case Either Text (Snaplet a)
    eb of
                Left e :: Text
    e -> Either Text (Snaplet a) -> IO (Either Text (Snaplet a))
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Either Text (Snaplet a) -> IO (Either Text (Snaplet a)))
    -> Either Text (Snaplet a) -> IO (Either Text (Snaplet a))
    forall a b. (a -> b) -> a -> b
    $ Text -> Either Text (Snaplet a)
    forall a b. a -> Either a b
    Left Text
    e
                Right bres :: Snaplet a
    bres -> Either Text (Snaplet a) -> IO (Either Text (Snaplet a))
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Either Text (Snaplet a) -> IO (Either Text (Snaplet a)))
    -> Either Text (Snaplet a) -> IO (Either Text (Snaplet a))
    forall a b. (a -> b) -> a -> b
    $ Snaplet a -> Either Text (Snaplet a)
    forall a b. b -> Either a b
    Right Snaplet a
    bres

    ------------------------------------------------------------------------------
    instance Monoid (Hook a) where
        mempty :: Hook a
    mempty = (Snaplet a -> IO (Either Text (Snaplet a))) -> Hook a
    forall a. (Snaplet a -> IO (Either Text (Snaplet a))) -> Hook a
    Hook (Either Text (Snaplet a) -> IO (Either Text (Snaplet a))
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Either Text (Snaplet a) -> IO (Either Text (Snaplet a)))
    -> (Snaplet a -> Either Text (Snaplet a))
    -> Snaplet a
    -> IO (Either Text (Snaplet a))
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Snaplet a -> Either Text (Snaplet a)
    forall a b. b -> Either a b
    Right)
    #if !MIN_VERSION_base(4,11,0)
        mappend = (<>)
    #endif

    ------------------------------------------------------------------------------
    -- | Monad used for initializing snaplets.
    newtype Initializer b v a =
        Initializer (LT.LensT (Snaplet b)
                              (Snaplet v)
                              (InitializerState b)
                              (WriterT (Hook b) IO)
                              a)
      deriving (Functor (Initializer b v)
    a -> Initializer b v a
    Functor (Initializer b v) =>
    (forall a. a -> Initializer b v a)
    -> (forall a b.
        Initializer b v (a -> b) -> Initializer b v a -> Initializer b v b)
    -> (forall a b c.
        (a -> b -> c)
        -> Initializer b v a -> Initializer b v b -> Initializer b v c)
    -> (forall a b.
        Initializer b v a -> Initializer b v b -> Initializer b v b)
    -> (forall a b.
        Initializer b v a -> Initializer b v b -> Initializer b v a)
    -> Applicative (Initializer b v)
    Initializer b v a -> Initializer b v b -> Initializer b v b
    Initializer b v a -> Initializer b v b -> Initializer b v a
    Initializer b v (a -> b) -> Initializer b v a -> Initializer b v b
    (a -> b -> c)
    -> Initializer b v a -> Initializer b v b -> Initializer b v c
    forall a. a -> Initializer b v a
    forall b v. Functor (Initializer b v)
    forall a b.
    Initializer b v a -> Initializer b v b -> Initializer b v a
    forall a b.
    Initializer b v a -> Initializer b v b -> Initializer b v b
    forall a b.
    Initializer b v (a -> b) -> Initializer b v a -> Initializer b v b
    forall b v a. a -> Initializer b v a
    forall a b c.
    (a -> b -> c)
    -> Initializer b v a -> Initializer b v b -> Initializer b v c
    forall b v a b.
    Initializer b v a -> Initializer b v b -> Initializer b v a
    forall b v a b.
    Initializer b v a -> Initializer b v b -> Initializer b v b
    forall b v a b.
    Initializer b v (a -> b) -> Initializer b v a -> Initializer b v b
    forall b v a b c.
    (a -> b -> c)
    -> Initializer b v a -> Initializer b v b -> Initializer b v c
    forall (f :: * -> *).
    Functor f =>
    (forall a. a -> f a)
    -> (forall a b. f (a -> b) -> f a -> f b)
    -> (forall a b c. (a -> b -> c) -> f a -> f b -> f c)
    -> (forall a b. f a -> f b -> f b)
    -> (forall a b. f a -> f b -> f a)
    -> Applicative f
    <* :: Initializer b v a -> Initializer b v b -> Initializer b v a
    $c<* :: forall b v a b.
    Initializer b v a -> Initializer b v b -> Initializer b v a
    *> :: Initializer b v a -> Initializer b v b -> Initializer b v b
    $c*> :: forall b v a b.
    Initializer b v a -> Initializer b v b -> Initializer b v b
    liftA2 :: (a -> b -> c)
    -> Initializer b v a -> Initializer b v b -> Initializer b v c
    $cliftA2 :: forall b v a b c.
    (a -> b -> c)
    -> Initializer b v a -> Initializer b v b -> Initializer b v c
    <*> :: Initializer b v (a -> b) -> Initializer b v a -> Initializer b v b
    $c<*> :: forall b v a b.
    Initializer b v (a -> b) -> Initializer b v a -> Initializer b v b
    pure :: a -> Initializer b v a
    $cpure :: forall b v a. a -> Initializer b v a
    $cp1Applicative :: forall b v. Functor (Initializer b v)
    Applicative, a -> Initializer b v b -> Initializer b v a
    (a -> b) -> Initializer b v a -> Initializer b v b
    (forall a b. (a -> b) -> Initializer b v a -> Initializer b v b)
    -> (forall a b. a -> Initializer b v b -> Initializer b v a)
    -> Functor (Initializer b v)
    forall a b. a -> Initializer b v b -> Initializer b v a
    forall a b. (a -> b) -> Initializer b v a -> Initializer b v b
    forall b v a b. a -> Initializer b v b -> Initializer b v a
    forall b v a b. (a -> b) -> Initializer b v a -> Initializer b v b
    forall (f :: * -> *).
    (forall a b. (a -> b) -> f a -> f b)
    -> (forall a b. a -> f b -> f a) -> Functor f
    <$ :: a -> Initializer b v b -> Initializer b v a
    $c<$ :: forall b v a b. a -> Initializer b v b -> Initializer b v a
    fmap :: (a -> b) -> Initializer b v a -> Initializer b v b
    $cfmap :: forall b v a b. (a -> b) -> Initializer b v a -> Initializer b v b
    Functor, Applicative (Initializer b v)
    a -> Initializer b v a
    Applicative (Initializer b v) =>
    (forall a b.
     Initializer b v a -> (a -> Initializer b v b) -> Initializer b v b)
    -> (forall a b.
        Initializer b v a -> Initializer b v b -> Initializer b v b)
    -> (forall a. a -> Initializer b v a)
    -> Monad (Initializer b v)
    Initializer b v a -> (a -> Initializer b v b) -> Initializer b v b
    Initializer b v a -> Initializer b v b -> Initializer b v b
    forall a. a -> Initializer b v a
    forall b v. Applicative (Initializer b v)
    forall a b.
    Initializer b v a -> Initializer b v b -> Initializer b v b
    forall a b.
    Initializer b v a -> (a -> Initializer b v b) -> Initializer b v b
    forall b v a. a -> Initializer b v a
    forall b v a b.
    Initializer b v a -> Initializer b v b -> Initializer b v b
    forall b v a b.
    Initializer b v a -> (a -> Initializer b v b) -> Initializer b v b
    forall (m :: * -> *).
    Applicative m =>
    (forall a b. m a -> (a -> m b) -> m b)
    -> (forall a b. m a -> m b -> m b)
    -> (forall a. a -> m a)
    -> Monad m
    return :: a -> Initializer b v a
    $creturn :: forall b v a. a -> Initializer b v a
    >> :: Initializer b v a -> Initializer b v b -> Initializer b v b
    $c>> :: forall b v a b.
    Initializer b v a -> Initializer b v b -> Initializer b v b
    >>= :: Initializer b v a -> (a -> Initializer b v b) -> Initializer b v b
    $c>>= :: forall b v a b.
    Initializer b v a -> (a -> Initializer b v b) -> Initializer b v b
    $cp1Monad :: forall b v. Applicative (Initializer b v)
    Monad, Monad (Initializer b v)
    Monad (Initializer b v) =>
    (forall a. IO a -> Initializer b v a) -> MonadIO (Initializer b v)
    IO a -> Initializer b v a
    forall a. IO a -> Initializer b v a
    forall b v. Monad (Initializer b v)
    forall b v a. IO a -> Initializer b v a
    forall (m :: * -> *).
    Monad m =>
    (forall a. IO a -> m a) -> MonadIO m
    liftIO :: IO a -> Initializer b v a
    $cliftIO :: forall b v a. IO a -> Initializer b v a
    $cp1MonadIO :: forall b v. Monad (Initializer b v)
    MonadIO)

    makeLenses ''InitializerState

    ------------------------------------------------------------------------------
    instance MonadSnaplet Initializer where
        getLens :: Initializer b v (SnapletLens (Snaplet b) v)
    getLens = LensT
      (Snaplet b)
      (Snaplet v)
      (InitializerState b)
      (WriterT (Hook b) IO)
      (SnapletLens (Snaplet b) v)
    -> Initializer b v (SnapletLens (Snaplet b) v)
    forall b v a.
    LensT
      (Snaplet b)
      (Snaplet v)
      (InitializerState b)
      (WriterT (Hook b) IO)
      a
    -> Initializer b v a
    Initializer LensT
      (Snaplet b)
      (Snaplet v)
      (InitializerState b)
      (WriterT (Hook b) IO)
      (SnapletLens (Snaplet b) v)
    forall r (m :: * -> *). MonadReader r m => m r
    ask
        with' :: SnapletLens (Snaplet v) v'
    -> Initializer b v' a -> Initializer b v a
    with' !SnapletLens (Snaplet v) v'
    l (Initializer !LensT
      (Snaplet b)
      (Snaplet v')
      (InitializerState b)
      (WriterT (Hook b) IO)
      a
    m) = LensT
      (Snaplet b)
      (Snaplet v)
      (InitializerState b)
      (WriterT (Hook b) IO)
      a
    -> Initializer b v a
    forall b v a.
    LensT
      (Snaplet b)
      (Snaplet v)
      (InitializerState b)
      (WriterT (Hook b) IO)
      a
    -> Initializer b v a
    Initializer (LensT
       (Snaplet b)
       (Snaplet v)
       (InitializerState b)
       (WriterT (Hook b) IO)
       a
     -> Initializer b v a)
    -> LensT
         (Snaplet b)
         (Snaplet v)
         (InitializerState b)
         (WriterT (Hook b) IO)
         a
    -> Initializer b v a
    forall a b. (a -> b) -> a -> b
    $ SnapletLens (Snaplet v) v'
    -> LensT
         (Snaplet b)
         (Snaplet v')
         (InitializerState b)
         (WriterT (Hook b) IO)
         a
    -> LensT
         (Snaplet b)
         (Snaplet v)
         (InitializerState b)
         (WriterT (Hook b) IO)
         a
    forall (m :: * -> *) v v' b s a.
    Monad m =>
    ALens' v v' -> LensT b v' s m a -> LensT b v s m a
    LT.with SnapletLens (Snaplet v) v'
    l LensT
      (Snaplet b)
      (Snaplet v')
      (InitializerState b)
      (WriterT (Hook b) IO)
      a
    m
        withTop' :: SnapletLens (Snaplet b) v'
    -> Initializer b v' a -> Initializer b v a
    withTop' !SnapletLens (Snaplet b) v'
    l (Initializer m :: LensT
      (Snaplet b)
      (Snaplet v')
      (InitializerState b)
      (WriterT (Hook b) IO)
      a
    m) = LensT
      (Snaplet b)
      (Snaplet v)
      (InitializerState b)
      (WriterT (Hook b) IO)
      a
    -> Initializer b v a
    forall b v a.
    LensT
      (Snaplet b)
      (Snaplet v)
      (InitializerState b)
      (WriterT (Hook b) IO)
      a
    -> Initializer b v a
    Initializer (LensT
       (Snaplet b)
       (Snaplet v)
       (InitializerState b)
       (WriterT (Hook b) IO)
       a
     -> Initializer b v a)
    -> LensT
         (Snaplet b)
         (Snaplet v)
         (InitializerState b)
         (WriterT (Hook b) IO)
         a
    -> Initializer b v a
    forall a b. (a -> b) -> a -> b
    $ SnapletLens (Snaplet b) v'
    -> LensT
         (Snaplet b)
         (Snaplet v')
         (InitializerState b)
         (WriterT (Hook b) IO)
         a
    -> LensT
         (Snaplet b)
         (Snaplet v)
         (InitializerState b)
         (WriterT (Hook b) IO)
         a
    forall (m :: * -> *) b v' s a v.
    Monad m =>
    ALens' b v' -> LensT b v' s m a -> LensT b v s m a
    LT.withTop SnapletLens (Snaplet b) v'
    l LensT
      (Snaplet b)
      (Snaplet v')
      (InitializerState b)
      (WriterT (Hook b) IO)
      a
    m
        getOpaqueConfig :: Initializer b v SnapletConfig
    getOpaqueConfig = LensT
      (Snaplet b)
      (Snaplet v)
      (InitializerState b)
      (WriterT (Hook b) IO)
      SnapletConfig
    -> Initializer b v SnapletConfig
    forall b v a.
    LensT
      (Snaplet b)
      (Snaplet v)
      (InitializerState b)
      (WriterT (Hook b) IO)
      a
    -> Initializer b v a
    Initializer (LensT
       (Snaplet b)
       (Snaplet v)
       (InitializerState b)
       (WriterT (Hook b) IO)
       SnapletConfig
     -> Initializer b v SnapletConfig)
    -> LensT
         (Snaplet b)
         (Snaplet v)
         (InitializerState b)
         (WriterT (Hook b) IO)
         SnapletConfig
    -> Initializer b v SnapletConfig
    forall a b. (a -> b) -> a -> b
    $ (InitializerState b -> SnapletConfig)
    -> LensT
         (Snaplet b)
         (Snaplet v)
         (InitializerState b)
         (WriterT (Hook b) IO)
         (InitializerState b)
    -> LensT
         (Snaplet b)
         (Snaplet v)
         (InitializerState b)
         (WriterT (Hook b) IO)
         SnapletConfig
    forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
    liftM InitializerState b -> SnapletConfig
    forall b. InitializerState b -> SnapletConfig
    _curConfig LensT
      (Snaplet b)
      (Snaplet v)
      (InitializerState b)
      (WriterT (Hook b) IO)
      (InitializerState b)
    forall (m :: * -> *) b v s. Monad m => LensT b v s m s
    LT.getBase

    ------------------------------------------------------------------------------
    -- | Opaque newtype which gives us compile-time guarantees that the user is
    -- using makeSnaplet and either nestSnaplet or embedSnaplet correctly.
    newtype SnapletInit b v = SnapletInit (Initializer b v (Snaplet v))