diff options
Diffstat (limited to 'src/vylist')
-rw-r--r-- | src/vylist/vylist.ml | 17 | ||||
-rw-r--r-- | src/vylist/vylist.mli | 3 |
2 files changed, 20 insertions, 0 deletions
diff --git a/src/vylist/vylist.ml b/src/vylist/vylist.ml new file mode 100644 index 0000000..c7d0396 --- /dev/null +++ b/src/vylist/vylist.ml @@ -0,0 +1,17 @@ +let rec find p xs = + match xs with + | [] -> None + | x :: xs' -> if (p x) then (Some x) + else find p xs' + +let rec remove p xs = + match xs with + | [] -> [] + | x :: xs' -> if (p x) then xs' + else x :: (remove p xs) + +let rec replace p x xs= + match xs with + | [] -> [] + | x' :: xs' -> if (p x') then x :: xs' + else x' :: (replace p x xs') diff --git a/src/vylist/vylist.mli b/src/vylist/vylist.mli new file mode 100644 index 0000000..266ec95 --- /dev/null +++ b/src/vylist/vylist.mli @@ -0,0 +1,3 @@ +val find : ('a -> bool) -> 'a list -> 'a option +val remove : ('a -> bool) -> 'a list -> 'a list +val replace : ('a -> bool) -> 'a -> 'a list -> 'a list |