Permalink
Browse files

Add MonadReader instance for Handler

  • Loading branch information...
1 parent 57beb28 commit 7a5f14bc2597583978404c3f84281320b1763d91 @mightybyte mightybyte committed Feb 4, 2013
Showing with 12 additions and 0 deletions.
  1. +12 −0 src/Snap/Snaplet/Internal/Types.hs
@@ -277,6 +277,18 @@ instance MonadState v (Handler b v) where
put v = modifySnapletState (set snapletValue v)
+------------------------------------------------------------------------------
+-- | The MonadState instance gives you access to the current snaplet's state.
+instance MonadReader v (Handler b v) where
+ ask = getsSnapletState _snapletValue
+ local f m = do
+ cur <- ask
+ put (f cur)
+ res <- m
+ put cur
+ return res
+
+
instance MonadSnaplet Handler where
getLens = Handler ask
with' !l (Handler !m) = Handler $ L.with l m

0 comments on commit 7a5f14b

Please sign in to comment.