File tree Expand file tree Collapse file tree 3 files changed +32
-31
lines changed
Expand file tree Collapse file tree 3 files changed +32
-31
lines changed Original file line number Diff line number Diff line change 1+ include List
2+
3+ let rec concat_map ?sep ~f = function
4+ | [] -> []
5+ | [ x ] -> f x
6+ | x :: xs -> (
7+ let hd = f x in
8+ let tl = concat_map ?sep ~f xs in
9+ match sep with None -> hd @ tl | Some sep -> hd @ (sep :: tl))
10+
11+ let rec filter_map acc f = function
12+ | hd :: tl ->
13+ let acc = match f hd with Some x -> x :: acc | None -> acc in
14+ filter_map acc f tl
15+ | [] -> List. rev acc
16+
17+ let filter_map f x = filter_map [] f x
18+
19+ (* * @raise [Failure] if the list is empty. *)
20+ let rec last = function
21+ | [] -> failwith " Odoc_utils.List.last"
22+ | [ x ] -> x
23+ | _ :: tl -> last tl
24+
25+ (* From ocaml/ocaml *)
26+ let rec find_map f = function
27+ | [] -> None
28+ | x :: l -> (
29+ match f x with Some _ as result -> result | None -> find_map f l)
Original file line number Diff line number Diff line change @@ -45,37 +45,7 @@ module EitherMonad = struct
4545 let of_result = function Result. Ok x -> Right x | Error y -> Left y
4646end
4747
48- module List = struct
49- include List
50-
51- let rec concat_map ?sep ~f = function
52- | [] -> []
53- | [ x ] -> f x
54- | x :: xs -> (
55- let hd = f x in
56- let tl = concat_map ?sep ~f xs in
57- match sep with None -> hd @ tl | Some sep -> hd @ (sep :: tl))
58-
59- let rec filter_map acc f = function
60- | hd :: tl ->
61- let acc = match f hd with Some x -> x :: acc | None -> acc in
62- filter_map acc f tl
63- | [] -> List. rev acc
64-
65- let filter_map f x = filter_map [] f x
66-
67- (* * @raise [Failure] if the list is empty. *)
68- let rec last = function
69- | [] -> failwith " Odoc_utils.List.last"
70- | [ x ] -> x
71- | _ :: tl -> last tl
72-
73- (* From ocaml/ocaml *)
74- let rec find_map f = function
75- | [] -> None
76- | x :: l -> (
77- match f x with Some _ as result -> result | None -> find_map f l)
78- end
48+ module List = Odoc_list
7949
8050module Option = struct
8151 let map f = function None -> None | Some x -> Some (f x)
Original file line number Diff line number Diff line change 1+ module List = Odoc_list
2+
13type 'a tree = { node : 'a ; children : 'a forest }
24and 'a forest = 'a tree list
35
You can’t perform that action at this time.
0 commit comments