Closed ghost closed 5 years ago
@Kove-W-O-Salter Thanks! I think you can use foldr1
to make it more simplified ?
Yes, that would be very readable. The only thing is that it will fail if checkDirs
is []
. Do you want me to change it?
Do you want me to change it?
Yes, checkDirs
here will be always non empty.
Finished. I've changed the definition of getPagePath
to:
getPagePath :: String -> IO (Maybe FilePath)
getPagePath page = do
homeDir <- getHomeDirectory
let pageDir = homeDir </> tldrDirName </> "tldr" </> "pages"
paths = map (\x -> pageDir </> x </> page <.> "md") checkDirs
foldr1 (<|>) <$> mapM pageExists paths
Thanks!
Thank you :smile:.
The problem
The definition of
Main.getPagePath
is dependant on the length ofMain.checkDirs
:This over complicates the process of adding new directories to
Main.checkDirs
.The solution
Modify
Main.getPagePath
's definition to take advantage ofControl.Monad
's utilities. The result is: