Skip to content

Commit

Permalink
Improve getPagePath
Browse files Browse the repository at this point in the history
  • Loading branch information
Kove W. Ochre-Salter committed Nov 20, 2018
1 parent 4fe8cff commit c9f8027
Showing 1 changed file with 2 additions and 12 deletions.
14 changes: 2 additions & 12 deletions app/Main.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{-#LANGUAGE CPP#-}
{-#LANGUAGE ScopedTypeVariables#-}

module Main where
Expand Down Expand Up @@ -84,17 +83,8 @@ getPagePath :: String -> IO (Maybe FilePath)
getPagePath page = do
homeDir <- getHomeDirectory
let pageDir = homeDir </> tldrDirName </> "tldr" </> "pages"
x@(f1:f2:f3:f4:[]) = map (\x -> pageDir </> x </> page <.> "md") checkDirs
#if MIN_VERSION_base(4,7,0)
f1' <- pageExists f1
f2' <- pageExists f2
f3' <- pageExists f3
f4' <- pageExists f4
return $ f1' <|> f2' <|> f3' <|> f4'
#else
pageExists f1 <|> pageExists f2 <|> pageExists f3 <|> pageExists f4
#endif

paths = map (\x -> pageDir </> x </> page <.> "md") checkDirs
foldr (<|>) Nothing <$> mapM pageExists paths

main :: IO ()
main = do
Expand Down

0 comments on commit c9f8027

Please sign in to comment.