update lib_utils

This commit is contained in:
Galfour 2019-04-20 18:52:28 +00:00
parent ecc509ad4c
commit 50926c205e
7 changed files with 29 additions and 8 deletions

View File

@ -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

View File

@ -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

View File

@ -1,3 +0,0 @@
let unopt ~default = function
| None -> default
| Some x -> x

View File

@ -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

View File

@ -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

View File

@ -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

View 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