packages feed

apiary 0.6.0.1 → 0.6.1.0

raw patch · 4 files changed

+15/−18 lines, 4 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Control.Monad.Apiary.Filter.Internal: focus :: (SList c -> ActionT IO (SList c')) -> ApiaryT c' m a -> ApiaryT c m a

Files

apiary.cabal view
@@ -1,5 +1,5 @@ name:                apiary-version:             0.6.0.1+version:             0.6.1.0 synopsis:            Simple web framework inspired by scotty. description:   Simple web framework inspired by scotty.
src/Control/Monad/Apiary/Filter/Internal.hs view
@@ -1,13 +1,16 @@-module Control.Monad.Apiary.Filter.Internal where+module Control.Monad.Apiary.Filter.Internal+    ( function, function', function_, focus+    ) where  import Control.Monad import Control.Monad.Apiary.Internal+import Control.Monad.Apiary.Action import Network.Wai import Data.Apiary.SList --- | raw and most generic filter function.+-- | low level filter function. function :: Monad m => (SList c -> Request -> Maybe (SList c')) -> ApiaryT c' m b -> ApiaryT c m b-function f = focus $ \r c -> case f c r of+function f = focus $ \c -> getRequest >>= \r -> case f c r of     Nothing -> mzero     Just c' -> return c' @@ -18,5 +21,3 @@ -- | filter only(not modify arguments). function_ :: Monad m => (Request -> Bool) -> ApiaryT c m b -> ApiaryT c m b function_ f = function $ \c r -> if f r then Just c else Nothing--
src/Control/Monad/Apiary/Internal.hs view
@@ -13,7 +13,6 @@  import Network.Wai import Control.Applicative-import Control.Monad import Data.Monoid import Data.Apiary.SList @@ -21,16 +20,12 @@  newtype ApiaryT c m a = ApiaryT { unApiaryT :: forall b.     (forall x . m x -> IO x)-    -> (Request -> Maybe (SList c))+    -> ActionT IO (SList c)     -> ApiaryConfig     -> (a -> ActionT IO () -> m b)     -> m b      } -filterToActionT :: Monad m => (Request -> Maybe (SList a))-                -> ActionT m (SList a)-filterToActionT f = getRequest >>= maybe mzero return . f- instance Functor (ApiaryT c m) where     fmap f m = ApiaryT $ \run grd conf cont ->         unApiaryT m run grd conf $ \a hdr -> hdr `seq` cont (f a) hdr@@ -52,7 +47,7 @@         in hdr'' `seq` cont b hdr''  runApiaryT :: Monad m => ApiaryConfig -> (forall x. m x -> IO x) -> ApiaryT '[] m a -> Application-runApiaryT conf run m req = run (unApiaryT m run (\_ -> Just SNil) conf (\_ w -> return w)) >>= \a ->+runApiaryT conf run m req = run (unApiaryT m run (return SNil) conf (\_ w -> return w)) >>= \a ->     execActionT conf a req  type Apiary c = ApiaryT c IO@@ -63,7 +58,7 @@ getRunner :: Monad m => ApiaryT c m (ActionT m a -> ActionT IO a) getRunner = ApiaryT $ \run _ _ c -> c (hoistActionT run) mempty -getGuard :: ApiaryT c m (Request -> Maybe (SList c))+getGuard :: ApiaryT c m (ActionT IO (SList c)) getGuard = ApiaryT $ \_ grd _ c -> c grd mempty  apiaryConfig :: ApiaryT c m ApiaryConfig@@ -72,10 +67,11 @@ addRoute :: ActionT IO () -> ApiaryT c m () addRoute r = ApiaryT $ \_ _ _ cont -> cont () r -focus :: Monad m => (Request -> SList c -> Maybe (SList c')) -> ApiaryT c' m b -> ApiaryT c m b+-- | filter by action. since 0.6.1.0.+focus :: (SList c -> ActionT IO (SList c')) -> ApiaryT c' m a -> ApiaryT c m a focus g m = do     ApiaryT $ \run grd cfg cont ->-        unApiaryT m run (\r -> grd r >>= \c -> g r c) cfg cont+        unApiaryT m run (grd >>= g) cfg cont  action :: Monad m => Fn c (ActionT m ()) -> ApiaryT c m () action = actionWithPreAction (const $ return ())@@ -86,4 +82,4 @@ actionWithPreAction pa a = do     tr  <- getRunner     grd <- getGuard-    addRoute $ filterToActionT grd >>= \c -> (pa c) >> tr (apply a c)+    addRoute $ grd >>= \c -> (pa c) >> tr (apply a c)
src/Data/Apiary/SList.hs view
@@ -24,7 +24,7 @@ type instance Fn (x ': xs) r = x -> Fn xs r  type family Snoc (as :: [*]) a :: [*]-type instance Snoc '[] a = '[a]+type instance Snoc '[] a = a ': '[] type instance Snoc (x ': xs) a = x ': Snoc xs a  type family All (c :: * -> Constraint) (as :: [*]) :: Constraint