package clarity

  1. Overview
  2. Docs

Efficient persistent vectors based on RRB-Trees

RRB (Relaxed Radix-Balanced) Trees allows "effectively constant" operations like getting element / updating at index, appending and splitting.

type 'a t
exception Out_of_bounds of {
  1. index : int;
  2. size : int;
}
val empty : 'a t

Empty vector.

val length : 'a t -> int

The length of a vector.

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

init l f creates vector of length l where value at position i is initialized with f i.

val append : 'a t -> 'a t -> 'a t

Concatenates two vectors. "Effectively constant".

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

get v i returns the element of a v at position i. "Effectively constant".

Raise Out_of_bounds when i is outside of v bounds.

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

update v i x returns new vector initialized with values of v where value at index i is replaced with x. "Effectively constant".

Raise Out_of_bounds when i is outside of v bounds.

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

split_at v i returns pair of a vectors where first element is the prefix of v of length i and second is the suffix of v starting at i. "Effectively constant".

Raise Out_of_bounds when i is negative.

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

take v i returns the prefix of v of length i. "Effectively constant".

Raise Out_of_bounds when i is negative.

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

drop v i returns the suffix of v starting at i. "Effectively constant".

Raise Out_of_bounds when i is negative.

val iter : ('a -> unit) -> 'a t -> unit

iter f v iterates over v applying f to each element.

val of_list : 'a list -> 'a t

Converts list to vector

val to_list : 'a t -> 'a list

Converts vector to list

include Monad.S with type 'a t := 'a t
include Monad.Basic with type 'a t := 'a t
include Applicative.Basic with type 'a t := 'a t
include Functor.Basic with type 'a t := 'a t
val bind : ('a -> 'b t) -> 'a t -> 'b t
include Applicative.S with type 'a t := 'a t
include Applicative.Basic with type 'a t := 'a t
include Functor.Basic with type 'a t := 'a t
val pure : 'a -> 'a t
val ap : ('a -> 'b) t -> (unit -> 'a t) -> 'b t
include Functor.S with type 'a t := 'a t
include Functor.Basic with type 'a t := 'a t
val map : ('a -> 'b) -> 'a t -> 'b t
val (>|=) : 'a t -> ('a -> 'b) -> 'b t
val replace : 'a -> 'b t -> 'a t
val void : 'a t -> unit t
val ap' : ('a -> 'b) t -> 'a t -> 'b t
val (<*>) : ('a -> 'b) t -> 'a t -> 'b t
val (<~>) : ('a -> 'b) t -> (unit -> 'a t) -> 'b t
val discard_left : 'a t -> (unit -> 'b t) -> 'b t
val discard_right : 'a t -> (unit -> 'b t) -> 'a t
val repeat : int -> 'a t -> 'a list t
val repeat_ : int -> 'a t -> unit t
val forever : 'a t -> 'b t
val (>>=) : 'a t -> ('a -> 'b t) -> 'b t
val join : 'a t t -> 'a t
val mcompose : ('b -> 'c t) -> ('a -> 'b t) -> 'a -> 'c t
include Foldable.S with type 'a t := 'a t
include Foldable.Basic with type 'a t := 'a t
val foldl : ('a -> 'b -> 'a) -> 'a -> 'b t -> 'a
val foldr : ('a -> (unit -> 'b) -> 'b) -> (unit -> 'b) -> 'a t -> 'b
val foldr' : ('a -> 'b -> 'b) -> 'b -> 'a t -> 'b
val fold_map : (module Monoid.S with type t = 'm) -> ('a -> 'm) -> 'a t -> 'm
val any : ('a -> bool) -> 'a t -> bool
val all : ('a -> bool) -> 'a t -> bool
val find : ('a -> bool) -> 'a t -> 'a option
include Align.S with type 'a t := 'a t
include Align.Basic with type 'a t := 'a t
val align_with : (('a, 'b) These.t -> 'c) -> 'a t -> 'b t -> 'c t
val align : 'a t -> 'b t -> ('a, 'b) These.t t
val falign : ('a -> 'a -> 'a) -> 'a t -> 'a t -> 'a t
val pad_zip_with : ('a option -> 'b option -> 'c) -> 'a t -> 'b t -> 'c t
val pad_zip : 'a t -> 'b t -> ('a option * 'b option) t
module A (A : Applicative.Basic) : Traversable.S with type 'a t := 'a t and type 'a f := 'a A.t
module A2 (A : Applicative.Basic2) : Traversable.S2 with type 'a t := 'a t and type ('u, 'a) f := ('u, 'a) A.t
module A3 (A : Applicative.Basic3) : Traversable.S3 with type 'a t := 'a t and type ('u, 'v, 'a) f := ('u, 'v, 'a) A.t
module M (M : Monad.Basic) : sig ... end
module M2 (M : Monad.Basic2) : sig ... end
module M3 (M : Monad.Basic3) : sig ... end
OCaml

Innovation. Community. Security.