package containers

  1. Overview
  2. Docs

complements to list

type 'a t = 'a list
val empty : 'a t
val map : ('a -> 'b) -> 'a t -> 'b t

Safe version of map

val (>|=) : 'a t -> ('a -> 'b) -> 'b t

Infix version of map with reversed arguments

  • since 0.5
val append : 'a t -> 'a t -> 'a t

Safe version of append

val (@) : 'a t -> 'a t -> 'a t
val filter : ('a -> bool) -> 'a t -> 'a t

Safe version of List.filter

val fold_right : ('a -> 'b -> 'b) -> 'a t -> 'b -> 'b

Safe version of fold_right

val init : int -> (int -> 'a) -> 'a t

Same as Array.init

  • since 0.6
val compare : ('a -> 'a -> int) -> 'a t -> 'a t -> int
val equal : ('a -> 'a -> bool) -> 'a t -> 'a t -> bool
val flat_map : ('a -> 'b t) -> 'a t -> 'b t

map and flatten at the same time (safe). Evaluation order is not guaranteed.

val flatten : 'a t t -> 'a t

Safe flatten

val product : ('a -> 'b -> 'c) -> 'a t -> 'b t -> 'c t

cartesian product of the two lists, with the given combinator

val fold_product : ('c -> 'a -> 'b -> 'c) -> 'c -> 'a t -> 'b t -> 'c

Fold on the cartesian product

val diagonal : 'a t -> ('a * 'a) t

All pairs of distinct positions of the list. list_diagonal l will return the list of List.nth i l, List.nth j l if i < j.

val pure : 'a -> 'a t
val (<*>) : ('a -> 'b) t -> 'a t -> 'b t
val (<$>) : ('a -> 'b) -> 'a t -> 'b t
val return : 'a -> 'a t
val (>>=) : 'a t -> ('a -> 'b t) -> 'b t
val take : int -> 'a t -> 'a t

take the n first elements, drop the rest

val drop : int -> 'a t -> 'a t

drop the n first elements, keep the rest

val split : int -> 'a t -> 'a t * 'a t

split n l returns l1, l2 such that l1 @ l2 = l and length l1 = min (length l) n

val last : int -> 'a t -> 'a t

last n l takes the last n elements of l (or less if l doesn't have that many elements

val find : ('a -> 'b option) -> 'a t -> 'b option

find f l traverses l, applying f to each element. If for some element x, f x = Some y, then Some y is returned. Otherwise the call returns None

val findi : (int -> 'a -> 'b option) -> 'a t -> 'b option

Like find, but also pass the index to the predicate function.

  • since 0.3.4
val find_idx : ('a -> bool) -> 'a t -> (int * 'a) option

find p x returns Some (i,x) where x is the i-th element of l, and p x holds. Otherwise returns None

val filter_map : ('a -> 'b option) -> 'a t -> 'b t

Map and remove elements at the same time

val sorted_merge : ?cmp:('a -> 'a -> int) -> 'a list -> 'a list -> 'a list

merges elements from both sorted list, removing duplicates

val sort_uniq : ?cmp:('a -> 'a -> int) -> 'a list -> 'a list

Sort the list and remove duplicate elements

Indices

module Idx : sig ... end

Set Operators

module Set : sig ... end

Other Constructors

val range : int -> int -> int t

range i j iterates on integers from i to j included . It works both for decreasing and increasing ranges

val range' : int -> int -> int t

Same as range but the second bound is excluded. For instance range' 0 5 = [0;1;2;3;4]

val (--) : int -> int -> int t

Infix alias for range

val replicate : int -> 'a -> 'a t

replicate the given element n times

val repeat : int -> 'a t -> 'a t

concatenate the list with itself n times

Association Lists

module Assoc : sig ... end

Zipper

module Zipper : sig ... end

References on Lists

  • since 0.3.3
module Ref : sig ... end
module type MONAD = sig ... end
module Traverse (M : MONAD) : sig ... end

Conversions

type 'a sequence = ('a -> unit) -> unit
type 'a gen = unit -> 'a option
type 'a klist = unit -> [ `Nil | `Cons of 'a * 'a klist ]
type 'a printer = Buffer.t -> 'a -> unit
type 'a formatter = Format.formatter -> 'a -> unit
type 'a random_gen = Random.State.t -> 'a
val random : 'a random_gen -> 'a t random_gen
val random_non_empty : 'a random_gen -> 'a t random_gen
val random_len : int -> 'a random_gen -> 'a t random_gen
val random_choose : 'a t -> 'a random_gen

Randomly choose an element in the list.

  • raises Not_found

    if the list is empty

val random_sequence : 'a random_gen t -> 'a t random_gen
val to_seq : 'a t -> 'a sequence
val of_seq : 'a sequence -> 'a t
val to_gen : 'a t -> 'a gen
val of_gen : 'a gen -> 'a t
val to_klist : 'a t -> 'a klist
val of_klist : 'a klist -> 'a t

IO

val pp : ?start:string -> ?stop:string -> ?sep:string -> 'a printer -> 'a t printer
val print : ?start:string -> ?stop:string -> ?sep:string -> 'a formatter -> 'a t formatter