package links

  1. Overview
  2. Docs
On This Page
  1. Lists

Lists

val empty : 'a list -> bool

Test whether the argument is the empty list.

val fromTo : int -> int -> int list

fromTo a b is the list of consecutive integers starting with a and ending with b-1. Throws Invalid_argument "fromTo" if b < a.

val mapIndex : ('a -> int -> 'b) -> 'a0 list -> 'b0 list

map with index

val all_equiv : ('a -> 'a -> bool) -> 'a0 list -> bool

all_equiv rel list: given an equiv. rel'n rel, determine whether all elements of list are equivalent.

val span : ('a -> bool) -> 'a0 list -> 'a0 list * 'a0 list

span pred list: partition list into an initial sublist satisfying pred and the remainder.

val groupBy : ('a -> 'a0 -> bool) -> 'a1 list -> 'a1 list list

groupBy rel list: given a binary rel'n rel, partition list into chunks s.t. successive elements x, y in a chunk give the same value under rel.

val groupByPred : ('a -> 'b) -> 'c list -> 'd list list

groupByPred pred partitions list into chunks where all elements in the chunk give the same value under pred.

val groupByPred' : ('a -> 'b) -> 'a0 list -> 'a0 list list

groupByPred': Alternate implementation of groupByPred.

val unsnoc : 'a list -> 'b list * 'c

unsnoc list: Partition list into its last element and all the others.

  • returns

    (others, lastElem)

val unsnoc_opt : 'a list -> ('a list * 'a) option

unsnoc_opt list: Partition list into its last element and all the others.

  • returns

    Some (others, lastElem) or None if the list is empty.

val last : 'a list -> 'b

last list: Return the last element of a list

val last_opt : 'a list -> 'b option

last_opt list: Return the last element of a list, or None if the list is empty.

val curtail : 'a list -> 'a list

curtail list: Return a copy of the list with the last element removed.

val difference : 'a list -> 'b list -> 'a list
val remove_all : 'a list -> 'a list -> 'a list
val subset : 'a list -> 'b list -> bool
val less_to_cmp : ('a -> 'b -> bool) -> 'c -> 'd -> int

Convert a (bivalent) less-than function into a (three-valued) comparison function.

val has_duplicates : 'a list -> bool

Checks whether list contains duplicates

val unduplicate : ('a -> 'b -> bool) -> 'c list -> 'd list

Remove duplicates from a list, using the given relation to determine `duplicates'

val collect_duplicates : ('a -> 'b -> bool) -> 'c list -> 'd list

Collects only elements which are duplicate in the original list.

val ordered_consecutive : int list -> bool
val drop : int -> 'a list -> 'a list
val take : int -> 'a list -> 'b list
val split : int -> 'a list -> 'b list * 'a list
val remove : 'a -> 'b list -> 'b list
val concat_map : ('a -> 'b list) -> 'a list -> 'b list
val concat_map_uniq : ('a -> 'b list) -> 'a list -> 'c list
val concat_map_undup : ('a -> 'a -> bool) -> ('b -> 'c list) -> 'b list -> 'a list
val for_each : 'a list -> ('a -> unit) -> unit
val push_back : 'a -> 'b list ref -> unit
val push_front : 'a -> 'b list ref -> unit
val split3 : ('a * 'b * 'c) list -> 'd list * 'e list * 'f list
val split4 : ('a * 'b * 'c * 'd) list -> 'e list * 'f list * 'g list * 'h list
val drop_nth : 'a list -> int -> 'a list
val filter_map : ('a -> bool) -> ('b -> 'c) -> 'd list -> 'e list
exception Lists_length_mismatch
val filter_map2 : (('a * 'b) -> bool) -> (('c * 'd) -> 'e) -> 'f list -> 'g list -> 'h list

Filter on two lists and map them together. Equivalent to map -<- filter -<- zip precondition: the two lists must be the same length

val map_filter : ('a -> 'b) -> ('c -> bool) -> 'd list -> 'e list
val print_list : string list -> string
val zip : 'a list -> 'b list -> ('c * 'd) list
val zip_with : ('a -> 'b -> 'c) -> 'd list -> 'e list -> 'f list
val split_with : ('a -> 'b * 'c) -> 'a list -> 'b list * 'c list
val zip' : 'a list -> 'b list -> ('c * 'd) list
val zip_with' : ('a -> 'b -> 'c) -> 'd list -> 'e list -> 'f list
val transpose : 'a list list -> 'a0 list list
OCaml

Innovation. Community. Security.