Created
July 10, 2014 15:19
-
-
Save imalsogreg/5064b5ebfda78d595357 to your computer and use it in GitHub Desktop.
Control.Error reduce nested cases
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
instance ISessionManager RedisSessionManager where | |
-------------------------------------------------------------------------- | |
--load grabs the session from redis. | |
load mgr@(RedisSessionManager (Just _) _ _ _ _ _ ) = return mgr | |
load mgr@(RedisSessionManager _ _ _ _ rng con) = do | |
res <- runMaybeT $ do | |
(Payload x) <- MaybeT $ getPayload mgr | |
cs <- hoistMaybe . hush $ S.decode x | |
liftIO $ runRedis con $ do | |
l <- hush <$> hgetall (sessionKey $ rsCSRFToken cs) | |
maybe (liftIO $ mkCookieSession rng) | |
(\l' -> return $ cs {rsSession = HM.fromList $ map decodeTuple l'}) l | |
maybe (liftIO $ loadDefSession mgr) | |
(\s -> return $ mgr {session = Just s}) res |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment