Skip to content

Commit

Permalink
Improved code style by using mapM instead of sequence
Browse files Browse the repository at this point in the history
  • Loading branch information
ad-si committed Mar 15, 2024
1 parent 6f74569 commit 8ef0bcf
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions tasklite-core/app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import Protolude (
Semigroup ((<>)),
Show,
Text,
Traversable (sequence),
die,
filter,
foldMap,
Expand Down Expand Up @@ -1279,24 +1278,26 @@ printOutput appName config = do
hookFiles <- listDirectory hooksPathNorm

hookFilesPerm :: [(FilePath, Permissions)] <-
sequence $
hookFiles
& filter
( \name ->
("pre-" `isPrefixOf` name) || ("post-" `isPrefixOf` name)
)
<&> (hooksPathNorm </>)
<&> \path -> do
perm <- getPermissions path
pure (path, perm)
hookFiles
& filter
( \name ->
("pre-" `isPrefixOf` name) || ("post-" `isPrefixOf` name)
)
<&> (hooksPathNorm </>)
& P.mapM
( \path -> do
perm <- getPermissions path
pure (path, perm)
)

hookFilesPermContent <-
sequence $
hookFilesPerm
& filter (\(_, perm) -> executable perm)
<&> \(filePath, perm) -> do
fileContent <- readFile filePath
pure (filePath, perm, fileContent)
hookFilesPerm
& filter (\(_, perm) -> executable perm)
& P.mapM
( \(filePath, perm) -> do
fileContent <- readFile filePath
pure (filePath, perm, fileContent)
)

let configNorm = addHookFilesToConfig configNormHookDir hookFilesPermContent

Expand All @@ -1306,7 +1307,7 @@ printOutput appName config = do
connection <- setupConnection configNorm

-- For debugging SQLite interactions
-- SQLite.setTrace connection $ Just print
-- SQLite.setTrace connection $ Just P.print

migrationsStatus <- runMigrations configNorm connection
nowElapsed <- timeCurrentP
Expand Down

0 comments on commit 8ef0bcf

Please sign in to comment.