summaryrefslogtreecommitdiff
path: root/src/util.ml
diff options
context:
space:
mode:
Diffstat (limited to 'src/util.ml')
-rw-r--r--src/util.ml22
1 files changed, 20 insertions, 2 deletions
diff --git a/src/util.ml b/src/util.ml
index 2b6f81f8..d2d4eea7 100644
--- a/src/util.ml
+++ b/src/util.ml
@@ -144,7 +144,14 @@ let rec compare_list f l1 l2 =
compare_list f l1 l2
else
c
-
+
+let rec split_on_char sep str =
+ try
+ let sep_pos = String.index str sep in
+ String.sub str 0 sep_pos :: split_on_char sep (String.sub str (sep_pos + 1) (String.length str - (sep_pos + 1)))
+ with
+ | Not_found -> [str]
+
let map_changed_default d f l =
let rec g = function
| [] -> ([],false)
@@ -196,6 +203,12 @@ let option_bind f = function
| None -> None
| Some(o) -> f o
+let rec option_binop f x y = match x, y with
+ | None, None -> None
+ | Some x, None -> Some x
+ | None, Some y -> Some y
+ | Some x, Some y -> Some (f x y)
+
let changed2 f g x h y =
match (g x, h y) with
| (None,None) -> None
@@ -240,6 +253,12 @@ let split_after n l =
| _ -> raise (Failure "index too large")
in aux [] n l
+let rec split3 = function
+ | (x, y, z) :: xs ->
+ let (xs, ys, zs) = split3 xs in
+ (x :: xs, y :: ys, z :: zs)
+ | [] -> ([], [], [])
+
let list_mapi (f : int -> 'a -> 'b) (l : 'a list) : 'b list =
let rec aux f i l =
match l with
@@ -324,4 +343,3 @@ let rec string_of_list sep string_of = function
| [] -> ""
| [x] -> string_of x
| x::ls -> (string_of x) ^ sep ^ (string_of_list sep string_of ls)
-