Introduce unzipping and use it
Šī revīzija ir iekļauta:
		@@ -9,8 +9,12 @@ module DependencyGenerator
 | 
			
		||||
  , mapDepGenM
 | 
			
		||||
  , mapDepGenM_
 | 
			
		||||
  , filterDepGenM
 | 
			
		||||
  , unzipFstDepGenM
 | 
			
		||||
  , unzipSndDepGenM
 | 
			
		||||
  , unzipDepGenM
 | 
			
		||||
 | 
			
		||||
  , joinPaths
 | 
			
		||||
  , fileComponents
 | 
			
		||||
  , isImageFilename
 | 
			
		||||
  , convertedImageFilename
 | 
			
		||||
  , applyTemplate
 | 
			
		||||
@@ -98,6 +102,27 @@ filterDepGenM f input = do
 | 
			
		||||
  conds <- mapDepGenM f input
 | 
			
		||||
  genDependency (makeDependency (TupleToken (input, conds)) FilterComp)
 | 
			
		||||
 | 
			
		||||
unzipFstDepGenM :: TokenableTo [(a, b)] t => t -> DepGenM (Token [a])
 | 
			
		||||
unzipFstDepGenM t = do
 | 
			
		||||
  t' <- toToken t
 | 
			
		||||
  case t' of
 | 
			
		||||
    ZipToken (a, _) -> pure a
 | 
			
		||||
    Token _ -> genDependency (makeDependency t' UnzipFst)
 | 
			
		||||
 | 
			
		||||
unzipSndDepGenM :: TokenableTo [(a, b)] t => t -> DepGenM (Token [b])
 | 
			
		||||
unzipSndDepGenM t = do
 | 
			
		||||
  t' <- toToken t
 | 
			
		||||
  case t' of
 | 
			
		||||
    ZipToken (_, b) -> pure b
 | 
			
		||||
    Token _ -> genDependency (makeDependency t' UnzipSnd)
 | 
			
		||||
 | 
			
		||||
unzipDepGenM :: TokenableTo [(a, b)] t => t -> DepGenM (Token [a], Token [b])
 | 
			
		||||
unzipDepGenM t = do
 | 
			
		||||
  t' <- toToken t
 | 
			
		||||
  a <- unzipFstDepGenM t'
 | 
			
		||||
  b <- unzipSndDepGenM t'
 | 
			
		||||
  pure (a, b)
 | 
			
		||||
 | 
			
		||||
class TokenableTo t s | s -> t where
 | 
			
		||||
  toToken :: s -> DepGenM' t
 | 
			
		||||
 | 
			
		||||
@@ -113,6 +138,9 @@ joinPaths (a, b) = do
 | 
			
		||||
  b' <- toToken b
 | 
			
		||||
  runFunction JoinPaths $ TupleToken (a', b')
 | 
			
		||||
 | 
			
		||||
fileComponents :: TokenableTo FilePath a => a -> DepGenM' (String, String)
 | 
			
		||||
fileComponents a = runFunction FileComponents =<< toToken a
 | 
			
		||||
 | 
			
		||||
isImageFilename :: TokenableTo FilePath a => a -> DepGenM' Bool
 | 
			
		||||
isImageFilename a = runFunction IsImageFilename =<< toToken a
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -6,6 +6,7 @@ import DependencyGenerator
 | 
			
		||||
handleRecipeDir :: Token FilePath -> Token Template -> Token FilePath -> DepGenM ()
 | 
			
		||||
handleRecipeDir outputDir template dir = do
 | 
			
		||||
  dirContents <- listDirectory dir
 | 
			
		||||
  (bases, exts) <- unzipDepGenM (mapDepGenM fileComponents dirContents)
 | 
			
		||||
  imageFilenames <- filterDepGenM isImageFilename dirContents
 | 
			
		||||
  convertedImageFilenames <- mapDepGenM convertedImageFilename imageFilenames
 | 
			
		||||
  mapDepGenM_
 | 
			
		||||
 
 | 
			
		||||
@@ -23,6 +23,8 @@ data Action = Function Function
 | 
			
		||||
            | FilterComp
 | 
			
		||||
            | GetListElem
 | 
			
		||||
            | SetListElem
 | 
			
		||||
            | UnzipFst
 | 
			
		||||
            | UnzipSnd
 | 
			
		||||
            | MapComp [Dependency]
 | 
			
		||||
  deriving (Show, Lift)
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -5,6 +5,7 @@ module Types.Function
 | 
			
		||||
import Language.Haskell.TH.Syntax (Lift)
 | 
			
		||||
 | 
			
		||||
data Function = JoinPaths
 | 
			
		||||
              | FileComponents
 | 
			
		||||
              | IsImageFilename
 | 
			
		||||
              | ConvertedImageFilename
 | 
			
		||||
              | ApplyTemplate
 | 
			
		||||
 
 | 
			
		||||
		Atsaukties uz šo jaunā problēmā
	
	Block a user