From 00ba7e1cbec7393caf23f562ef2b1c571feb4480 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Hamal=20Dvo=C5=99=C3=A1k?= <mordae@anilinux.org> Date: Sun, 17 Nov 2019 14:50:00 +0100 Subject: [PATCH] Simplify get*Maybe functions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jan Hamal Dvořák <mordae@anilinux.org> --- lib/Hikaru/Action.hs | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/lib/Hikaru/Action.hs b/lib/Hikaru/Action.hs index fd76370..c1fd2cf 100644 --- a/lib/Hikaru/Action.hs +++ b/lib/Hikaru/Action.hs @@ -370,9 +370,9 @@ where -- on the fly to the target type. Parsing failure maps to 'Nothing'. -- getParamMaybe :: (MonadAction m, FromParam a) => Text -> m (Maybe a) - getParamMaybe n = lookup n <$> getParams - >>= \case Nothing -> return $ Nothing - Just val -> return $ fromParam val + getParamMaybe n = do + value <- lookup n <$> getParams + return $ fromParam =<< value -- | @@ -410,9 +410,9 @@ where -- Parsing failure maps to 'Nothing'. -- getCookieMaybe :: (MonadAction m, FromParam a) => Text -> m (Maybe a) - getCookieMaybe n = lookup n <$> getCookies - >>= \case Nothing -> return $ Nothing - Just val -> return $ fromParam val + getCookieMaybe n = do + value <- lookup n <$> getCookies + return $ fromParam =<< value -- | @@ -622,9 +622,9 @@ where -- Parsing failure maps to 'Nothing'. -- getFieldMaybe :: (MonadAction m, FromParam a) => Text -> m (Maybe a) - getFieldMaybe n = lookup n <$> getFields - >>= \case Nothing -> return $ Nothing - Just val -> return $ fromParam val + getFieldMaybe n = do + value <- lookup n <$> getFields + return $ fromParam =<< value -- | @@ -658,8 +658,6 @@ where -- getFileMaybe :: (MonadAction m) => Text -> m (Maybe (FileInfo FilePath)) getFileMaybe n = lookup n <$> getFiles - >>= \case Nothing -> return $ Nothing - Just val -> return $ Just val -- | -- GitLab