summaryrefslogtreecommitdiffstats
path: root/lib/prelude.ml
blob: 57f7af348ec5b18cfbd6d8aa34ae965f845a0847 (about) (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
include Core
module Time_ns = Time_ns_unix

module List = struct
  include List

  let map_result ~(f : 'a -> ('b, 'c) result) : 'a list -> ('b list, 'c) result
      =
    let open Result.Let_syntax in
    let rec go = function
      | [] -> return []
      | x :: xs ->
          let%map x' = f x and xs' = go xs in
          x' :: xs'
    in
    go
end

module Z = struct
  include Z

  let sexp_of_t x = Sexp.Atom (Z.to_string x)
end

module Result = struct
  include Result

  let unwrap = function
    | Error _ -> failwith "Result.unwrap: unexpected (Error _)"
    | Ok v -> v
end