Skip to content

Instantly share code, notes, and snippets.

@imalsogreg
Created July 10, 2014 15:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save imalsogreg/5064b5ebfda78d595357 to your computer and use it in GitHub Desktop.
Save imalsogreg/5064b5ebfda78d595357 to your computer and use it in GitHub Desktop.
Control.Error reduce nested cases
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