From ecdb14837e06dcc826bc9c1d9c7b939da3fb28b1 Mon Sep 17 00:00:00 2001 From: Daniil Baturin Date: Sat, 28 Feb 2015 08:56:35 +0600 Subject: Factor out list operations from vytree. --- src/vylist/vylist.ml | 17 +++++++++++++++++ src/vylist/vylist.mli | 3 +++ 2 files changed, 20 insertions(+) create mode 100644 src/vylist/vylist.ml create mode 100644 src/vylist/vylist.mli (limited to 'src/vylist') 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 -- cgit v1.2.3