this repo has no description
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at main 84 lines 2.7 kB view raw
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 Uses a Buffer to accumulate output and writes it to the file in one 62 go at the end. This avoids per-chunk channel mutex acquisition in 63 the multicore runtime. *) 64 let with_formatter_out fname f = 65 let buf = Buffer.create 65536 in 66 let fmt = Format.formatter_of_buffer buf in 67 let result = f fmt in 68 Format.pp_print_flush fmt (); 69 with_open_out fname (fun oc -> Buffer.output_buffer oc buf); 70 result 71 72 (** Shortcuts for composing [with_open_*] functions and [Marshal]. *) 73 let marshal fname v = 74 with_open_out_bin fname (fun oc -> Marshal.to_channel oc v []) 75 76 let unmarshal fname = with_open_in_bin fname Marshal.from_channel 77end 78 79module Int = struct 80 include Int 81 let max x y : t = if x >= y then x else y 82end 83 84include Astring