Skip to content

Commit ac2599b

Browse files
committed
Compatibility
1 parent 35ad0aa commit ac2599b

File tree

3 files changed

+32
-31
lines changed

3 files changed

+32
-31
lines changed

src/utils/odoc_list.ml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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)

src/utils/odoc_utils.ml

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -45,37 +45,7 @@ module EitherMonad = struct
4545
let of_result = function Result.Ok x -> Right x | Error y -> Left y
4646
end
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

8050
module Option = struct
8151
let map f = function None -> None | Some x -> Some (f x)

src/utils/tree.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
module List = Odoc_list
2+
13
type 'a t = { node : 'a; children : 'a forest }
24
and 'a forest = 'a t list
35

0 commit comments

Comments
 (0)