aboutsummaryrefslogtreecommitdiff
path: root/src/Util/ListUtil.v
diff options
context:
space:
mode:
authorGravatar Jason Gross <jagro@google.com>2018-07-24 16:35:19 -0400
committerGravatar Jason Gross <jagro@google.com>2018-07-24 16:35:19 -0400
commit8772868f6b3796d6dd83a76ba2d0525388a71117 (patch)
tree28bc3f17f22da3cf5fce72f2574b50f3401c78af /src/Util/ListUtil.v
parentec7e744cfdeb3462b13c3f27809cb4b192ea542a (diff)
Add ListUtil.{take,drop}_while
Diffstat (limited to 'src/Util/ListUtil.v')
-rw-r--r--src/Util/ListUtil.v12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/Util/ListUtil.v b/src/Util/ListUtil.v
index f9e3457a1..3e0313800 100644
--- a/src/Util/ListUtil.v
+++ b/src/Util/ListUtil.v
@@ -331,6 +331,18 @@ Definition set_nth {T} n x (xs:list T)
Definition splice_nth {T} n (x:T) xs := firstn n xs ++ x :: skipn (S n) xs.
Hint Unfold splice_nth.
+Fixpoint take_while {T} (f : T -> bool) (ls : list T) : list T
+ := match ls with
+ | nil => nil
+ | cons x xs => if f x then x :: @take_while T f xs else nil
+ end.
+
+Fixpoint drop_while {T} (f : T -> bool) (ls : list T) : list T
+ := match ls with
+ | nil => nil
+ | cons x xs => if f x then @drop_while T f xs else x :: xs
+ end.
+
Ltac boring :=
simpl; intuition auto with zarith datatypes;
repeat match goal with