[commit: ghc] wip/nfs-locking: Add Expressions.removePair function to remove pairs of arguments. (9140548)
git at git.haskell.org
git at git.haskell.org
Thu Oct 26 23:50:00 UTC 2017
Repository : ssh://git@git.haskell.org/ghc
On branch : wip/nfs-locking
Link : http://ghc.haskell.org/trac/ghc/changeset/9140548b75f96d17e9888a21bf32a2f46d447cbe/ghc
>---------------------------------------------------------------
commit 9140548b75f96d17e9888a21bf32a2f46d447cbe
Author: Andrey Mokhov <andrey.mokhov at gmail.com>
Date: Wed Dec 30 03:03:26 2015 +0000
Add Expressions.removePair function to remove pairs of arguments.
>---------------------------------------------------------------
9140548b75f96d17e9888a21bf32a2f46d447cbe
src/Expression.hs | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/src/Expression.hs b/src/Expression.hs
index 2b7ef9a..a2eaea9 100644
--- a/src/Expression.hs
+++ b/src/Expression.hs
@@ -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
More information about the ghc-commits
mailing list