Commit 018f8501 authored by Andrey Mokhov's avatar Andrey Mokhov
Browse files

Add productArgs and concatArgs helper functions.

parent f913c358
...@@ -12,12 +12,12 @@ module Base ( ...@@ -12,12 +12,12 @@ module Base (
Condition (..), Condition (..),
(<+>), (<+>),
filterOut, filterOut,
prefixArgs productArgs, concatArgs
) where ) where
import Development.Shake import Development.Shake hiding ((*>))
import Development.Shake.FilePath import Development.Shake.FilePath
import Control.Applicative hiding ((*>)) import Control.Applicative
import Data.Function import Data.Function
import Data.Monoid import Data.Monoid
import Data.List import Data.List
...@@ -32,9 +32,10 @@ instance Monoid a => Monoid (Action a) where ...@@ -32,9 +32,10 @@ instance Monoid a => Monoid (Action a) where
mempty = return mempty mempty = return mempty
mappend p q = mappend <$> p <*> q mappend p q = mappend <$> p <*> q
-- Using the Creators' trick for overlapping String instances
class ShowArgs a where class ShowArgs a where
showArgs :: a -> Args showArgs :: a -> Args
showListArgs :: [a] -> Args -- the Creators' trick for overlapping String instances showListArgs :: [a] -> Args
showListArgs = mconcat . map showArgs showListArgs = mconcat . map showArgs
instance ShowArgs Char where instance ShowArgs Char where
...@@ -62,8 +63,18 @@ filterOut as exclude = do ...@@ -62,8 +63,18 @@ filterOut as exclude = do
exclude' <- showArgs exclude exclude' <- showArgs exclude
filter (`notElem` exclude') <$> as filter (`notElem` exclude') <$> as
-- Prefix each arg in a collection with a given prefix -- Generate a cross product collection of two argument collections
prefixArgs :: (ShowArgs a, ShowArgs b) => a -> b -> Args -- Example: productArgs ["-a", "-b"] "c" = arg ["-a", "c", "-b", "c"]
prefixArgs prefix as = do productArgs :: (ShowArgs a, ShowArgs b) => a -> b -> Args
prefix' <- showArgs prefix productArgs as bs = do
concatMap (\a -> prefix' ++ [a]) <$> showArgs as as' <- showArgs as
bs' <- showArgs bs
return $ concat $ sequence [as', bs']
-- Similar to productArgs but concat resulting arguments pairwise
-- Example: concatArgs ["-a", "-b"] "c" = arg ["-ac", "-bc"]
concatArgs :: (ShowArgs a, ShowArgs b) => a -> b -> Args
concatArgs as bs = do
as' <- showArgs as
bs' <- showArgs bs
return $ map concat $ sequence [as', bs']
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