Permalink
Browse files

Factor out allMonthFiles

Inside mostRecentMonthFile was code for finding all month files in the
timeline.  That's a handy, reusable chunk of code that we really want
separately accessible.
  • Loading branch information...
1 parent 8cb6109 commit 0afd2312329c5fa4ffe05b533d3a904ad884c5ad @mndrix committed Jul 23, 2010
Showing with 8 additions and 4 deletions.
  1. +8 −4 App/Clk/Util.hs
View
@@ -34,12 +34,16 @@ strptime = readTime defaultTimeLocale
isMonthFile :: FilePath -> Bool
isMonthFile p = p =~ "^[0-9]{4}-[0-9]{2}.txt$"
+allMonthFiles :: IO [MonthFile]
+allMonthFiles = do
+ clkDir <- getClkDir
+ let lineDir = clkDir </> "timeline"
+ paths <- fmap (map (lineDir</>)) $ getDirectoryContents lineDir
+ return $ mapMaybe maybeMonthFile $ map mkAbsolutePath paths
+
mostRecentMonthFile :: IO (Maybe MonthFile)
mostRecentMonthFile = do
- clkDir <- getClkDir
- let lineDir = clkDir </> "timeline"
- paths <- fmap (map (lineDir</>)) $ getDirectoryContents lineDir
- let monthFiles = mapMaybe maybeMonthFile $ map mkAbsolutePath paths
+ monthFiles <- allMonthFiles
case monthFiles of
[] -> return Nothing
fs -> return $ Just $ maximum fs

0 comments on commit 0afd231

Please sign in to comment.