From 1a67c2865df9e621b1b499c1bc4b3580ea66174b Mon Sep 17 00:00:00 2001 From: bruno Date: Tue, 19 Jun 2018 18:19:04 +0200 Subject: [PATCH] Protocol environment / List: update to 4.06.1 --- src/lib_protocol_environment/sigs/v1/list.mli | 65 ++++++++++++++++--- 1 file changed, 57 insertions(+), 8 deletions(-) diff --git a/src/lib_protocol_environment/sigs/v1/list.mli b/src/lib_protocol_environment/sigs/v1/list.mli index 9111dd45f..065d8db5f 100644 --- a/src/lib_protocol_environment/sigs/v1/list.mli +++ b/src/lib_protocol_environment/sigs/v1/list.mli @@ -29,6 +29,20 @@ val length : 'a list -> int (** Return the length (number of elements) of the given list. *) +val compare_lengths : 'a list -> 'b list -> int +(** Compare the lengths of two lists. [compare_lengths l1 l2] is + equivalent to [compare (length l1) (length l2)], except that + the computation stops after itering on the shortest list. + @since 4.05.0 +*) + +val compare_length_with : 'a list -> int -> int +(** Compare the length of a list to an integer. [compare_length_with l n] is + equivalent to [compare (length l) n], except that + the computation stops after at most [n] iterations on the list. + @since 4.05.0 +*) + val cons : 'a -> 'a list -> 'a list (** [cons x xs] is [x :: xs] @since 4.03.0 @@ -48,9 +62,24 @@ val nth : 'a list -> int -> 'a Raise [Failure "nth"] if the list is too short. Raise [Invalid_argument "List.nth"] if [n] is negative. *) +val nth_opt : 'a list -> int -> 'a option +(** Return the [n]-th element of the given list. + The first element (head of the list) is at position 0. + Return [None] if the list is too short. + Raise [Invalid_argument "List.nth"] if [n] is negative. + @since 4.05 +*) + val rev : 'a list -> 'a list (** List reversal. *) +val init : int -> (int -> 'a) -> 'a list +(** [List.init len f] is [f 0; f 1; ...; f (len-1)], evaluated left to right. + + @raise Invalid_argument if len < 0. + @since 4.06.0 +*) + val append : 'a list -> 'a list -> 'a list (** Concatenate two lists. Same as the infix operator [@]. Not tail-recursive (length of the first argument). *) @@ -70,7 +99,7 @@ val flatten : 'a list list -> 'a list (** An alias for [concat]. *) -(** {6 Iterators} *) +(** {1 Iterators} *) val iter : ('a -> unit) -> 'a list -> unit @@ -111,7 +140,7 @@ val fold_right : ('a -> 'b -> 'b) -> 'a list -> 'b -> 'b [f a1 (f a2 (... (f an b) ...))]. Not tail-recursive. *) -(** {6 Iterators on two lists} *) +(** {1 Iterators on two lists} *) val iter2 : ('a -> 'b -> unit) -> 'a list -> 'b list -> unit @@ -144,7 +173,7 @@ val fold_right2 : ('a -> 'b -> 'c -> 'c) -> 'a list -> 'b list -> 'c -> 'c to have different lengths. Not tail-recursive. *) -(** {6 List scanning} *) +(** {1 List scanning} *) val for_all : ('a -> bool) -> 'a list -> bool @@ -176,7 +205,7 @@ val memq : 'a -> 'a list -> bool equality to compare list elements. *) -(** {6 List searching} *) +(** {1 List searching} *) val find : ('a -> bool) -> 'a list -> 'a @@ -185,6 +214,12 @@ val find : ('a -> bool) -> 'a list -> 'a Raise [Not_found] if there is no value that satisfies [p] in the list [l]. *) +val find_opt: ('a -> bool) -> 'a list -> 'a option +(** [find_opt p l] returns the first element of the list [l] that + satisfies the predicate [p], or [None] if there is no value that + satisfies [p] in the list [l]. + @since 4.05 *) + val filter : ('a -> bool) -> 'a list -> 'a list (** [filter p l] returns all the elements of the list [l] that satisfy the predicate [p]. The order of the elements @@ -201,7 +236,7 @@ val partition : ('a -> bool) -> 'a list -> 'a list * 'a list The order of the elements in the input list is preserved. *) -(** {6 Association lists} *) +(** {1 Association lists} *) val assoc : 'a -> ('a * 'b) list -> 'b @@ -212,10 +247,24 @@ val assoc : 'a -> ('a * 'b) list -> 'b Raise [Not_found] if there is no value associated with [a] in the list [l]. *) +val assoc_opt: 'a -> ('a * 'b) list -> 'b option +(** [assoc_opt a l] returns the value associated with key [a] in the list of + pairs [l]. That is, + [assoc_opt a [ ...; (a,b); ...] = b] + if [(a,b)] is the leftmost binding of [a] in list [l]. + Returns [None] if there is no value associated with [a] in the + list [l]. + @since 4.05 *) + val assq : 'a -> ('a * 'b) list -> 'b (** Same as {!List.assoc}, but uses physical equality instead of structural equality to compare keys. *) +val assq_opt : 'a -> ('a * 'b) list -> 'b option +(** Same as {!List.assoc_opt}, but uses physical equality instead of structural + equality to compare keys. + @since 4.05 *) + val mem_assoc : 'a -> ('a * 'b) list -> bool (** Same as {!List.assoc}, but simply return true if a binding exists, and false if no bindings exist for the given key. *) @@ -234,7 +283,7 @@ val remove_assq : 'a -> ('a * 'b) list -> ('a * 'b) list of structural equality to compare keys. Not tail-recursive. *) -(** {6 Lists of pairs} *) +(** {1 Lists of pairs} *) val split : ('a * 'b) list -> 'a list * 'b list @@ -251,7 +300,7 @@ val combine : 'a list -> 'b list -> ('a * 'b) list have different lengths. Not tail-recursive. *) -(** {6 Sorting} *) +(** {1 Sorting} *) val sort : ('a -> 'a -> int) -> 'a list -> 'a list @@ -291,7 +340,7 @@ val merge : ('a -> 'a -> int) -> 'a list -> 'a list -> 'a list (** Merge two lists: Assuming that [l1] and [l2] are sorted according to the comparison function [cmp], [merge cmp l1 l2] will return a - sorted list containting all the elements of [l1] and [l2]. + sorted list containing all the elements of [l1] and [l2]. If several elements compare equal, the elements of [l1] will be before the elements of [l2]. Not tail-recursive (sum of the lengths of the arguments).