this repo has no description
1type msg = [ `Msg of string ]
2
3(** The [result] type and a bind operator. This module is meant to be opened. *)
4module ResultMonad = struct
5 let map_error f = function Ok _ as ok -> ok | Error e -> Error (f e)
6
7 let of_option ~error = function Some x -> Ok x | None -> Error error
8
9 let ( >>= ) = Result.bind
10end
11
12(** A bind operator for the [option] type. This module is meant to be opened. *)
13module OptionMonad = struct
14 (* The error case become [None], the error value is ignored. *)
15 let of_result = function Ok x -> Some x | Error _ -> None
16
17 let ( >>= ) = Option.bind
18end
19
20module List = Odoc_list
21
22module Tree = Tree
23module Forest = Tree.Forest
24module Json = Json
25
26module Io_utils = struct
27 (** [with_open_*] are resource safe wrappers around opening and closing
28 channels. They are equivalent to the same functions in OCaml 4.14's
29 [In_channel] and [Out_channel]. *)
30
31 let _with_resource res ~close f =
32 Fun.protect ~finally:(fun () -> close res) (fun () -> f res)
33
34 let with_open_in fname f =
35 _with_resource (open_in fname) ~close:close_in_noerr f
36
37 let with_open_in_bin fname f =
38 _with_resource (open_in_bin fname) ~close:close_in_noerr f
39
40 (** Read a file line-by-line by folding [f]. *)
41 let fold_lines fname f acc =
42 _with_resource (open_in fname) ~close:close_in_noerr (fun ic ->
43 let rec loop acc =
44 match input_line ic with
45 | exception End_of_file -> acc
46 | line -> loop (f line acc)
47 in
48 loop acc)
49
50 (** Read a file as a list of lines. *)
51 let read_lines fname =
52 List.rev (fold_lines fname (fun line acc -> line :: acc) [])
53
54 let with_open_out fname f =
55 _with_resource (open_out fname) ~close:close_out_noerr f
56
57 let with_open_out_bin fname f =
58 _with_resource (open_out_bin fname) ~close:close_out_noerr f
59
60 (** Like [with_open_out] but operate on a [Format] buffer. *)
61 let with_formatter_out fname f =
62 with_open_out fname (fun oc -> f (Format.formatter_of_out_channel oc))
63
64 (** Shortcuts for composing [with_open_*] functions and [Marshal]. *)
65 let marshal fname v =
66 with_open_out_bin fname (fun oc -> Marshal.to_channel oc v [])
67
68 let unmarshal fname = with_open_in_bin fname Marshal.from_channel
69end
70
71module Int = struct
72 include Int
73 let max x y : t = if x >= y then x else y
74end
75
76include Astring