diff options
author | Daniil Baturin <daniil@baturin.org> | 2015-02-28 08:56:35 +0600 |
---|---|---|
committer | Daniil Baturin <daniil@baturin.org> | 2015-02-28 08:56:35 +0600 |
commit | ecdb14837e06dcc826bc9c1d9c7b939da3fb28b1 (patch) | |
tree | a43df61f2b0d4dedef6bdb93324c77293ba0b541 /src/vylist | |
parent | 559715be78fdfa5d6f3a1756dfa0b8ebb7032228 (diff) | |
download | vyconf-ecdb14837e06dcc826bc9c1d9c7b939da3fb28b1.tar.gz vyconf-ecdb14837e06dcc826bc9c1d9c7b939da3fb28b1.zip |
Factor out list operations from vytree.
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 |