diff --git a/byg/src/ComputationM.hs b/byg/src/ComputationM.hs index d76ddac..476d9c7 100644 --- a/byg/src/ComputationM.hs +++ b/byg/src/ComputationM.hs @@ -1,8 +1,11 @@ module ComputationM ( ComputationM + , Token , evalComputationM , inject , mapComputationM + , mapComputationM_ + , filterComputationM , runFunction , runFunctionIO ) where @@ -19,11 +22,13 @@ data TypedRun a b where GetListElem :: TypedRun [b] b SetListElem :: TypedRun a [a] MapComp :: [DependencyUntyped] -> TypedRun [a] [b] + FilterComp :: TypedRun ([a], [Bool]) [a] deriving instance (Show a, Show b) => Show (TypedRun a b) data Token a where Token :: Int -> Token a + ZipToken :: Token a -> Token b -> Token (a, b) NoToken :: Token () deriving instance Show (Token a) @@ -90,3 +95,13 @@ mapComputationM f input = genDependency' $ \target -> do setListElem outp target put top' pure (Dependency input (MapComp res) target) + +mapComputationM_ :: Show a => (Token a -> ComputationM ()) -> Token [a] -> ComputationM () +mapComputationM_ f input = do + _ <- mapComputationM f input + pure NoToken + +filterComputationM :: Show a => (Token a -> ComputationM Bool) -> Token [a] -> ComputationM [a] +filterComputationM f input = do + conds <- mapComputationM f input + genDependency (Dependency (ZipToken input conds) FilterComp) diff --git a/byg/src/Main.hs b/byg/src/Main.hs index 34cec97..48f7f9a 100644 --- a/byg/src/Main.hs +++ b/byg/src/Main.hs @@ -3,11 +3,18 @@ module Main where import ComputationM import Functions +handleRecipeDir :: Token FilePath -> ComputationM () +handleRecipeDir dir = do + dirContents <- listDirectory dir + imageFilenames <- filterComputationM isImageFilename dirContents + t <- inject ("hej", "hey.txt") + saveFile t + test :: ComputationM () test = do dir <- inject "retter" dirContents <- listDirectory dir - _ <- mapComputationM openImage dirContents + mapComputationM_ handleRecipeDir dirContents t <- inject ("hej", "hey.txt") saveFile t