module Listutil:List-manipulation utilitiessig
..end
These functions are designed to augment the standard "Association lists"
functions in the standard library List. Association lists are lists
of pairs where the first item is a key and the second item is a value.
These utilities add functions similar to those you may find in the standard
module Hashtbl to work with association lists.
val replace : ('a * 'b) list -> 'a -> 'b -> ('a * 'b) list
replace l key value
will add a (key, value)
pair to the list.
If any pair with the same key already exists, it will be removed. Therefore,
this function can be thought of as doing the same task as the Hashtbl
module's replace function.(key, value)
pair added, replacing any existing
pair with the same key.l
: List to work withkey
: Key to addvalue
: Value to addval remove_assoc_all : ('a * 'b) list -> 'a -> ('a * 'b) list
remove_assoc_all l key
will remove all pairs from list l
with a key matching the given value, and returns the result.val sub : 'a list -> int -> int -> 'a list
sub l start len
,
a list with len
elements will be returned, with elements starting at
start
(where element 0 is the first element).Invalid_argument
If the start and len arguments are invalid
with respect to each other or the size of the list,
Invalid_argument "Listutil.sub"
is raised.val take : int -> 'a list -> 'a list
Raises Failure on invalid arguments or if n is greater than the length of the
list.
val drop : int -> 'a list -> 'a list
Raises Failure on invalid arguments or if n is greater than the length of
the list.
These functions do something with a list.
val output_lines : Pervasives.out_channel -> string list -> unit
val output_chars : Pervasives.out_channel -> char list -> unit