module Network.Salvia.Handlers.Dispatching ( Dispatcher , ListDispatcher , hDispatch , hListDispatch ) where import Control.Monad.State import Network.Salvia.Httpd type Dispatcher a b = a -> Handler b -> Handler b -> Handler b type ListDispatcher a b = [(a, Handler b)] -> Handler b -> Handler b hDispatch :: (Show c, Show a) => (Context -> c) -> (a -> c -> Bool) -> Dispatcher a b hDispatch f match a handler _default = do ctx <- gets f if a `match` ctx then handler else _default hListDispatch :: Dispatcher a b -> ListDispatcher a b hListDispatch disp = flip $ foldr $ uncurry disp