Commit 677d1109 by Zachary Snow

added monadic file traversal helper

parent 66989b04
...@@ -79,6 +79,7 @@ module Convert.Traverse ...@@ -79,6 +79,7 @@ module Convert.Traverse
, traverseScopesM , traverseScopesM
, scopedConversion , scopedConversion
, stately , stately
, traverseFilesM
, traverseFiles , traverseFiles
) where ) where
...@@ -1068,17 +1069,25 @@ stately mapper thing = do ...@@ -1068,17 +1069,25 @@ stately mapper thing = do
-- packages, or typenames in other files. Global resolution of modules and -- packages, or typenames in other files. Global resolution of modules and
-- interfaces is more commonly expected than global resolution of typenames and -- interfaces is more commonly expected than global resolution of typenames and
-- packages. -- packages.
traverseFiles traverseFilesM
:: Monoid w :: (Monoid w, Monad m)
=> CollectorM (Writer w) AST => CollectorM (Writer w) AST
-> (w -> Mapper AST) -> (w -> MapperM m AST)
-> Mapper [AST] -> MapperM m [AST]
traverseFiles fileCollectorM fileMapper files = traverseFilesM fileCollectorM fileMapperM files =
map traverseFile files mapM traverseFileM files
where where
globalNotes = execWriter $ mapM fileCollectorM files globalNotes = execWriter $ mapM fileCollectorM files
traverseFile file = traverseFileM file =
fileMapper notes file fileMapperM notes file
where where
localNotes = execWriter $ fileCollectorM file localNotes = execWriter $ fileCollectorM file
notes = localNotes <> globalNotes notes = localNotes <> globalNotes
traverseFiles
:: Monoid w
=> CollectorM (Writer w) AST
-> (w -> Mapper AST)
-> Mapper [AST]
traverseFiles fileCollectorM fileMapper files =
evalState (traverseFilesM fileCollectorM fileMapperM files) ()
where fileMapperM = (\w -> return . fileMapper w)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment