Module Listutil


module Listutil: sig  end
List-manipulation utilities



Association List Utilities

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
Calling 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.
Returns New list with a (key, value) pair added, replacing any existing pair with the same key.

l : List to work with
key : Key to add
value : Value to add
val remove_assoc_all : ('a * 'b) list -> 'a -> ('a * 'b) list
Calling remove_assoc_all l key will remove all pairs from list l with a key matching the given value, and returns the result.


Sub-List Selection


val sub : 'a list -> int -> int -> 'a list
This function behaves identically to the standard Array.sub or String.sub functions, but operates on lists. Given a call of sub l start len, a list with len elements will be returned, with elements starting at start (where element 0 is the first element).
Raises 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
This function returns the first n elements of the given list.

Raises Failure on invalid arguments or if n is greater than the length of the list.

val drop : int -> 'a list -> 'a list
This function removes the first n elements from the given list and returns the remaining elements.

Raises Failure on invalid arguments or if n is greater than the length of the list.



Processing Utilities

These functions do something with a list.

val output_lines : Pervasives.out_channel -> string list -> unit
Given a list of lines, output a line containing each element from the list. The list is expected to not have newlines; those will be added automatically.
val output_chars : Pervasives.out_channel -> char list -> unit
Given a list of chars, output the characters representing each element from the list.