package n_ary

  1. Overview
  2. Docs

Module N_ary.List3Source

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.

Sourceval 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.

Sourceval 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.

Sourceval 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.

Sourceval 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.

Sourceval 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.

Sourceval 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.

Sourceval 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.

Sourceval 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.

Sourceval 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.

Sourceval 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.

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.

Sourceval 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.

Sourceval 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.

Sourceval 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.

Sourceval 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.

Sourceval 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.

OCaml

Innovation. Community. Security.