Implement creating ZIP (JAR) files from tree of classes.
[hs-java.git] / Java / ClassPath / Common.hs
index e20286fc0897e8d3eeaf320640d6bcbe535ed492..e50b1e8ffd42bb174bdaac18ad1572fce81cab1a 100644 (file)
@@ -3,6 +3,7 @@ module Java.ClassPath.Common where
 
 import Data.List
 import Data.String.Utils (split)
+import System.FilePath
 
 import Java.ClassPath.Types
 
@@ -19,6 +20,15 @@ mapTM ::  (Monad m, Functor m) => (t -> m a) -> Tree t -> m (Tree a)
 mapTM fn (Directory dir forest) = Directory dir `fmap` mapFM fn forest
 mapTM fn (File a) = File `fmap` fn a
 
+mapFMF ::  (Monad m, Functor m) => (FilePath -> t -> m a) -> [Tree t] -> m [Tree a]
+mapFMF fn forest = mapM (mapTMF fn) forest
+
+mapTMF ::  (Monad m, Functor m) => (FilePath -> t -> m a) -> Tree t -> m (Tree a)
+mapTMF fn t = go "" t
+  where
+    go path (Directory dir forest) = Directory dir `fmap` mapM (go $ path </> dir) forest
+    go path (File a) = File `fmap` fn path a
+
 -- | map on tree
 mapT ::  (t -> a) -> Tree t -> Tree a
 mapT fn (Directory dir forest) = Directory dir (mapF fn forest)