package zarr

  1. Overview
  2. Docs

Source file util.ml

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
32
33
34
35
36
37
38
39
40
41
42
43
module ExtPoint = struct
  type 'a t =
    {name : string
    ;configuration : 'a}

  let ( = ) cmp x y =
    (x.name = y.name) &&
    cmp x.configuration y.configuration
end

module ArrayMap = struct
  include Map.Make (struct
    type t = int array
    let compare (x : t) (y : t) = Stdlib.compare x y
  end)

  let add_to_list k v map =
    update k (Option.fold ~none:(Some [v]) ~some:(fun l -> Some (v :: l))) map
end

module Result_syntax = struct
  let (let*) = Result.bind
  let (let+) x f = Result.map f x
end

let get_name j =
  Yojson.Safe.Util.(member "name" j |> to_string)

let prod x =
  Array.fold_left Int.mul 1 x

let max = Array.fold_left Int.max Int.min_int

(* Obtained from: https://discuss.ocaml.org/t/how-to-create-a-new-file-while-automatically-creating-any-intermediate-directories/14837/5?u=zoj613 *)
let rec create_parent_dir fn perm =
  let parent_dir = Filename.dirname fn in
  if not (Sys.file_exists parent_dir) then begin
    create_parent_dir parent_dir perm;
    Sys.mkdir parent_dir perm
  end

let sanitize_dir dir =
  Option.fold ~none:dir ~some:Fun.id @@ Filename.chop_suffix_opt ~suffix:"/" dir