package n_ary

  1. Overview
  2. Docs

Defines list operations that produce or consume 3 lists at once.

Partitioning Lists

These functions produce many lists from one by assigning each result from the input to one of 3 buckets.

val partition_enum : 'a Base.list -> f:('a -> Enum3.t) -> 'a Base.list * 'a Base.list * 'a Base.list

Transforms an input list into a tuple of lists. The Nth list is the elements of the input for which f returns CaseN, in the order they occur in the input.

val partition_enumi : 'a Base.list -> f:(Base.int -> 'a -> Enum3.t) -> 'a Base.list * 'a Base.list * 'a Base.list

Like partition_enum. f is also passed the index of the current list item.

val partition_map : 'a Base.list -> f:('a -> ('b0, 'b1, 'b2) Variant3.t) -> 'b0 Base.list * 'b1 Base.list * 'b2 Base.list

Transforms an input list into a tuple of lists. f is applied to every element of the input. For every result of the form CaseN x, the Nth output list contains x in the same order that the inputs occurred.

val partition_mapi : 'a Base.list -> f:(Base.int -> 'a -> ('b0, 'b1, 'b2) Variant3.t) -> 'b0 Base.list * 'b1 Base.list * 'b2 Base.list

Like partition_map. f is also passed the index of the current list item.

Unzipping Lists

These functions produces many lists from one by taking each part from a tuple into a separate list.

val unzip : ('a0 * 'a1 * 'a2) Base.list -> 'a0 Base.list * 'a1 Base.list * 'a2 Base.list

Transform a list of 3-tuples into a tuple of lists.

Zipping Lists

These functions produce one list from many by processing multiple corresponding elements at once to produce a single result.

Returning Unequal Lengths

These functions detect unequal lengths before they begin processing list elements, and return either Ok _ or Unequal_lengths.

val zip : 'a0 Base.list -> 'a1 Base.list -> 'a2 Base.list -> ('a0 * 'a1 * 'a2) Base.list Base.List.Or_unequal_lengths.t

Transform 3 lists of equal length into a single list of 3-tuples. Returns Unequal_lengths if the input lists don't all have the same length.

val map : 'a0 Base.list -> 'a1 Base.list -> 'a2 Base.list -> f:('a0 -> 'a1 -> 'a2 -> 'b) -> 'b Base.list Base.List.Or_unequal_lengths.t

Map a function over 3 lists simultaneously. If the input lists don't all have the same length, returns Unequal_lengths without calling f on any elements.

val mapi : 'a0 Base.list -> 'a1 Base.list -> 'a2 Base.list -> f:(Base.int -> 'a0 -> 'a1 -> 'a2 -> 'b) -> 'b Base.list Base.List.Or_unequal_lengths.t

Like map. f is also passed the index of the current list item.

val iter : 'a0 Base.list -> 'a1 Base.list -> 'a2 Base.list -> f:('a0 -> 'a1 -> 'a2 -> Base.unit) -> Base.unit Base.List.Or_unequal_lengths.t

Like map. Ignores the result; used for side-effecting functions.

val iteri : 'a0 Base.list -> 'a1 Base.list -> 'a2 Base.list -> f:(Base.int -> 'a0 -> 'a1 -> 'a2 -> Base.unit) -> Base.unit Base.List.Or_unequal_lengths.t

Like iter. f is also passed the index of the current list item.

val check_equal_lengths : _ Base.list -> _ Base.list -> _ Base.list -> Base.unit Base.List.Or_unequal_lengths.t

Returns Ok () if the input lists all have the same length. Returns Unequal_lengths otherwise.

Raising on Unequal Lengths

These functions begin processing list elements immediately. If one or more lists end before the others, they raise an exception.

val zip_exn : 'a0 Base.list -> 'a1 Base.list -> 'a2 Base.list -> ('a0 * 'a1 * 'a2) Base.list

Like zip, but raises if the input lists don't all have the same length.

val map_exn : 'a0 Base.list -> 'a1 Base.list -> 'a2 Base.list -> f:('a0 -> 'a1 -> 'a2 -> 'b) -> 'b Base.list

Like map. Raises if the input lists don't all have the same length. May call f before raising.

val mapi_exn : 'a0 Base.list -> 'a1 Base.list -> 'a2 Base.list -> f:(Base.int -> 'a0 -> 'a1 -> 'a2 -> 'b) -> 'b Base.list

Like map_exn. f is also passed the index of the current list item.

val iter_exn : 'a0 Base.list -> 'a1 Base.list -> 'a2 Base.list -> f:('a0 -> 'a1 -> 'a2 -> Base.unit) -> Base.unit

Like iter. Raises if the input lists don't all have the same length. May call f before raising.

val iteri_exn : 'a0 Base.list -> 'a1 Base.list -> 'a2 Base.list -> f:(Base.int -> 'a0 -> 'a1 -> 'a2 -> Base.unit) -> Base.unit

Like iter_exn. f is also passed the index of the current list item.