Skip to content

Commit

Permalink
Compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
panglesd committed Oct 18, 2024
1 parent 35ad0aa commit ac2599b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 31 deletions.
29 changes: 29 additions & 0 deletions src/utils/odoc_list.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
include List

let rec concat_map ?sep ~f = function
| [] -> []
| [ x ] -> f x
| x :: xs -> (
let hd = f x in
let tl = concat_map ?sep ~f xs in
match sep with None -> hd @ tl | Some sep -> hd @ (sep :: tl))

let rec filter_map acc f = function
| hd :: tl ->
let acc = match f hd with Some x -> x :: acc | None -> acc in
filter_map acc f tl
| [] -> List.rev acc

let filter_map f x = filter_map [] f x

(** @raise [Failure] if the list is empty. *)
let rec last = function
| [] -> failwith "Odoc_utils.List.last"
| [ x ] -> x
| _ :: tl -> last tl

(* From ocaml/ocaml *)
let rec find_map f = function
| [] -> None
| x :: l -> (
match f x with Some _ as result -> result | None -> find_map f l)
32 changes: 1 addition & 31 deletions src/utils/odoc_utils.ml
Original file line number Diff line number Diff line change
Expand Up @@ -45,37 +45,7 @@ module EitherMonad = struct
let of_result = function Result.Ok x -> Right x | Error y -> Left y
end

module List = struct
include List

let rec concat_map ?sep ~f = function
| [] -> []
| [ x ] -> f x
| x :: xs -> (
let hd = f x in
let tl = concat_map ?sep ~f xs in
match sep with None -> hd @ tl | Some sep -> hd @ (sep :: tl))

let rec filter_map acc f = function
| hd :: tl ->
let acc = match f hd with Some x -> x :: acc | None -> acc in
filter_map acc f tl
| [] -> List.rev acc

let filter_map f x = filter_map [] f x

(** @raise [Failure] if the list is empty. *)
let rec last = function
| [] -> failwith "Odoc_utils.List.last"
| [ x ] -> x
| _ :: tl -> last tl

(* From ocaml/ocaml *)
let rec find_map f = function
| [] -> None
| x :: l -> (
match f x with Some _ as result -> result | None -> find_map f l)
end
module List = Odoc_list

module Option = struct
let map f = function None -> None | Some x -> Some (f x)
Expand Down
2 changes: 2 additions & 0 deletions src/utils/tree.ml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module List = Odoc_list

type 'a t = { node : 'a; children : 'a forest }
and 'a forest = 'a t list

Expand Down

0 comments on commit ac2599b

Please sign in to comment.