update lib_utils
This commit is contained in:
parent
ecc509ad4c
commit
50926c205e
@ -18,6 +18,14 @@ let ne_list_sep value separator ppf (hd, tl) =
|
|||||||
let prepend s f ppf a =
|
let prepend s f ppf a =
|
||||||
fprintf ppf "%s%a" s f a
|
fprintf ppf "%s%a" s f a
|
||||||
|
|
||||||
|
let option = fun f ppf opt ->
|
||||||
|
match opt with
|
||||||
|
| Some x -> fprintf ppf "Some(%a)" f x
|
||||||
|
| None -> fprintf ppf "None"
|
||||||
|
|
||||||
|
let map = fun f pp ppf x ->
|
||||||
|
pp ppf (f x)
|
||||||
|
|
||||||
let pair_sep value sep ppf (a, b) = fprintf ppf "%a %s %a" value a sep value b
|
let pair_sep value sep ppf (a, b) = fprintf ppf "%a %s %a" value a sep value b
|
||||||
let smap_sep value sep ppf m =
|
let smap_sep value sep ppf m =
|
||||||
let module SMap = X_map.String in
|
let module SMap = X_map.String in
|
||||||
|
@ -27,7 +27,7 @@ module Assoc : DICTIONARY = struct
|
|||||||
|
|
||||||
let set ?equal lst a b =
|
let set ?equal lst a b =
|
||||||
let equal : 'a -> 'a -> bool =
|
let equal : 'a -> 'a -> bool =
|
||||||
Option.unopt
|
X_option.unopt
|
||||||
~default:(=) equal
|
~default:(=) equal
|
||||||
in
|
in
|
||||||
let rec aux acc = function
|
let rec aux acc = function
|
||||||
@ -39,7 +39,7 @@ module Assoc : DICTIONARY = struct
|
|||||||
|
|
||||||
let del ?equal lst a =
|
let del ?equal lst a =
|
||||||
let equal : 'a -> 'a -> bool =
|
let equal : 'a -> 'a -> bool =
|
||||||
Option.unopt
|
X_option.unopt
|
||||||
~default:(=) equal
|
~default:(=) equal
|
||||||
in
|
in
|
||||||
let rec aux acc = function
|
let rec aux acc = function
|
||||||
|
@ -1,3 +0,0 @@
|
|||||||
let unopt ~default = function
|
|
||||||
| None -> default
|
|
||||||
| Some x -> x
|
|
@ -14,7 +14,7 @@ module PP_helpers = PP
|
|||||||
module Location = Location
|
module Location = Location
|
||||||
|
|
||||||
module List = X_list
|
module List = X_list
|
||||||
module Option = Tezos_base.TzPervasives.Option
|
module Option = X_option
|
||||||
module Cast = Cast
|
module Cast = Cast
|
||||||
module Tuple = Tuple
|
module Tuple = Tuple
|
||||||
module Map = X_map
|
module Map = X_map
|
||||||
|
@ -334,13 +334,13 @@ module Assert = struct
|
|||||||
let assert_equal_int ?msg expected actual =
|
let assert_equal_int ?msg expected actual =
|
||||||
let msg =
|
let msg =
|
||||||
let default = Format.asprintf "Not equal int : expected %d, got %d" expected actual in
|
let default = Format.asprintf "Not equal int : expected %d, got %d" expected actual in
|
||||||
Option.unopt ~default msg in
|
X_option.unopt ~default msg in
|
||||||
assert_equal ~msg expected actual
|
assert_equal ~msg expected actual
|
||||||
|
|
||||||
let assert_equal_bool ?msg expected actual =
|
let assert_equal_bool ?msg expected actual =
|
||||||
let msg =
|
let msg =
|
||||||
let default = Format.asprintf "Not equal bool : expected %b, got %b" expected actual in
|
let default = Format.asprintf "Not equal bool : expected %b, got %b" expected actual in
|
||||||
Option.unopt ~default msg in
|
X_option.unopt ~default msg in
|
||||||
assert_equal ~msg expected actual
|
assert_equal ~msg expected actual
|
||||||
|
|
||||||
let assert_none ?(msg="not a none") opt = match opt with
|
let assert_none ?(msg="not a none") opt = match opt with
|
||||||
|
@ -108,4 +108,14 @@ module Append = struct
|
|||||||
match t with
|
match t with
|
||||||
| Empty -> None
|
| Empty -> None
|
||||||
| Full t' -> assoc_opt' t' k
|
| Full t' -> assoc_opt' t' k
|
||||||
|
|
||||||
|
let rec pp' : _ -> _ -> 'a t' -> unit = fun f ppf t' ->
|
||||||
|
match t' with
|
||||||
|
| Leaf x -> Format.fprintf ppf "%a" f x
|
||||||
|
| Node {a;b} -> Format.fprintf ppf "N(%a , %a)" (pp' f) a (pp' f) b
|
||||||
|
|
||||||
|
let pp : _ -> _ -> 'a t -> unit = fun f ppf t ->
|
||||||
|
match t with
|
||||||
|
| Empty -> Format.fprintf ppf "[]"
|
||||||
|
| Full x -> Format.fprintf ppf "[%a]" (pp' f) x
|
||||||
end
|
end
|
||||||
|
6
src/lib_utils/x_option.ml
Normal file
6
src/lib_utils/x_option.ml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
include Tezos_stdlib.Option
|
||||||
|
|
||||||
|
let lr (a , b) = match (a , b) with
|
||||||
|
| Some x , _ -> Some (`Left x)
|
||||||
|
| None , Some x -> Some (`Right x)
|
||||||
|
| _ -> None
|
Loading…
Reference in New Issue
Block a user