From baa1d0ce0998a4227e340edae8478cd2d31768bc Mon Sep 17 00:00:00 2001 From: Tissevert Date: Sat, 30 May 2020 12:57:52 +0200 Subject: [PATCH] Simplify inelegant code --- src/Blog.hs | 4 ++-- src/Files.hs | 15 ++++++--------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/Blog.hs b/src/Blog.hs index b49fd38..58ecd67 100644 --- a/src/Blog.hs +++ b/src/Blog.hs @@ -95,8 +95,8 @@ tagged collection path = do discover :: Path -> IO (Collection Article, Collection Page, Collection (Set String)) discover path = do - articles <- find (Article.at) $ articlesPath path - pages <- maybe (return Map.empty) (find (Page.at)) $ pagesPath path + articles <- find Article.at $ articlesPath path + pages <- maybe (return Map.empty) (find Page.at) $ pagesPath path tags <- Map.fromList . filter (not . Set.null . snd) <$> (Files.find (articlesPath path "tags") >>= mapM (articles `tagged`)) return (articles, pages, tags) diff --git a/src/Files.hs b/src/Files.hs index d82ea89..9a2326d 100644 --- a/src/Files.hs +++ b/src/Files.hs @@ -20,15 +20,12 @@ absoluteLink ('.':path) = path absoluteLink path = "/" path filePath :: File -> IO FilePath -filePath file = do - let (thePath, test, errorMessage) = - case file of - File path -> (path, doesFileExist, (++ ": no such file")) - Dir path -> (path, doesDirectoryExist, (++ ": no such directory")) - bool <- test thePath - if bool - then return thePath - else die $ errorMessage thePath +filePath (File path) = do + bool <- doesFileExist path + if bool then return path else die $ path ++ ": no such file" +filePath (Dir path) = do + bool <- doesDirectoryExist path + if bool then return path else die $ path ++ ": no such directory" find :: FilePath -> IO [FilePath] find path =