Commit 9140548b authored by Andrey Mokhov's avatar Andrey Mokhov

Add Expressions.removePair function to remove pairs of arguments.

parent 9e2ddcb1
......@@ -3,7 +3,8 @@ module Expression (
-- * Expressions
Expr, DiffExpr, fromDiffExpr,
-- ** Operators
apply, append, arg, remove, appendSub, appendSubD, filterSub, removeSub,
apply, append, arg, remove, removePair,
appendSub, appendSubD, filterSub, removeSub,
-- ** Evaluation
interpret, interpretPartial, interpretWithStage, interpretDiff,
-- ** Predicates
......@@ -76,6 +77,16 @@ append x = apply (<> x)
remove :: Eq a => [a] -> DiffExpr [a]
remove xs = apply $ filter (`notElem` xs)
-- | Remove given pair of elements from a list expression
-- Example: removePair "-flag" "b" ["-flag", "a", "-flag", "b"] = ["-flag", "a"]
removePair :: Eq a => a -> a -> DiffExpr [a]
removePair x y = apply filterPair
where
filterPair (z1 : z2 : zs) = if x == z1 && y == z2
then filterPair zs
else z1 : filterPair (z2 : zs)
filterPair zs = zs
-- | Apply a predicate to an expression
applyPredicate :: Monoid a => Predicate -> Expr a -> Expr a
applyPredicate predicate expr = do
......
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