this repo has no description
at main 46 lines 1.1 kB view raw
1include List 2 3let rec concat_map_sep ~sep ~f = function 4 | [] -> [] 5 | [ x ] -> f x 6 | x :: xs -> 7 let hd = f x in 8 let tl = concat_map_sep ~sep ~f xs in 9 hd @ (sep :: tl) 10 11(* Since 4.10 *) 12let concat_map f l = 13 let rec aux f acc = function 14 | [] -> rev acc 15 | x :: l -> 16 let xs = f x in 17 aux f (rev_append xs acc) l 18 in 19 aux f [] l 20 21(** @raise Failure if the list is empty. *) 22let rec last = function 23 | [] -> failwith "Odoc_utils.List.last" 24 | [ x ] -> x 25 | _ :: tl -> last tl 26 27(* Since 4.10. Copied ocaml/ocaml *) 28let rec find_map f = function 29 | [] -> None 30 | x :: l -> ( 31 match f x with Some _ as result -> result | None -> find_map f l) 32 33(* Since 5.1 *) 34let is_empty = function [] -> true | _ :: _ -> false 35 36let rec skip_until ~p = function 37 | [] -> [] 38 | h :: t -> if p h then t else skip_until ~p t 39 40let split_at ~f lst = 41 let rec loop acc = function 42 | hd :: _ as rest when f hd -> (List.rev acc, rest) 43 | [] -> (List.rev acc, []) 44 | hd :: tl -> loop (hd :: acc) tl 45 in 46 loop [] lst