summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/vylist.ml6
-rw-r--r--src/vylist.mli1
-rw-r--r--test/vylist_test.ml6
3 files changed, 13 insertions, 0 deletions
diff --git a/src/vylist.ml b/src/vylist.ml
index f18801e..dbcf906 100644
--- a/src/vylist.ml
+++ b/src/vylist.ml
@@ -38,3 +38,9 @@ let complement xs ys =
in
if List.length xs < List.length ys then aux xs ys
else aux ys xs
+
+let in_list xs x =
+ let x' = find ((=) x) xs in
+ match x' with
+ | None -> false
+ | Some _ -> true
diff --git a/src/vylist.mli b/src/vylist.mli
index 9a713b3..2df1c2f 100644
--- a/src/vylist.mli
+++ b/src/vylist.mli
@@ -4,3 +4,4 @@ val replace : ('a -> bool) -> 'a -> 'a list -> 'a list
val insert_before : ('a -> bool) -> 'a -> 'a list -> 'a list
val insert_after : ('a -> bool) -> 'a -> 'a list -> 'a list
val complement : 'a list -> 'a list -> 'a list option
+val in_list : 'a list -> 'a -> bool
diff --git a/test/vylist_test.ml b/test/vylist_test.ml
index 45336bb..8cd504b 100644
--- a/test/vylist_test.ml
+++ b/test/vylist_test.ml
@@ -55,6 +55,12 @@ let test_complement_doesnt_contain test_ctxt =
let xs = [1;2;3] and ys = [1;4;5;6] in
assert_equal (complement xs ys) None
+(* in_list works *)
+let test_in_list test_ctxt =
+ let xs = [1;2;3;4] in
+ assert_equal (in_list xs 3) true;
+ assert_equal (in_list xs 9) false
+
let suite =
"VyConf list tests" >::: [
"test_find_existent" >:: test_find_existent;