package batteries

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type
include module type of struct include BatArray.Cap end
Capabilities for arrays.

This modules provides the same set of features as Array, but with the added twist that arrays can be made read-only or write-only. Read-only arrays may then be safely shared and distributed.

There is no loss of performance involved.

type ('a, 'b) t = ('a, 'b) BatArray.Cap.t constraint 'b = [< `Read | `Write ]

The type of arrays with capabilities. An ('a, [`Read | `Write]) array behaves as a regular 'a array, while a ('a, [`Read]) array only has read-only capabilities and a ('a, [`Write]) array only has write-only capabilities.

Base operations
val length : ('a, [> ]) t -> int
val get : ('a, [> `Read ]) t -> int -> 'a
val set : ('a, [> `Write ]) t -> int -> 'a -> unit
Constructors
val make : int -> 'a -> ('a, _) t
val create : int -> 'a -> ('a, _) t
val make_float : int -> (float, _) t

Array.make_float n returns a fresh float array of length n, with uninitialized data.

  • since 2.3.0 and OCaml 4.2.0
val of_array : 'a array -> ('a, _) t

Adopt a regular array as a capability array, allowing to decrease capabilities if necessary.

This operation involves no copying. In other words, in let cap = of_array a in ..., any modification in a will also have effect on cap and reciprocally.

val to_array : ('a, [ `Read | `Write ]) t -> 'a array

Return a capability array as an array.

This operation requires both read and write permissions on the capability array and involves no copying. In other words, in let a = of_array cap in ..., any modification in a will also have effect on cap and reciprocally.

val read_only : ('a, [> `Read ]) t -> ('a, [ `Read ]) t

Drop to read-only permissions.

This operation involves no copying.

val write_only : ('a, [> `Write ]) t -> ('a, [ `Write ]) t

Drop to write-only permissions.

This operation involves no copying.

val init : int -> (int -> 'a) -> ('a, _) t
val make_matrix : int -> int -> 'a -> (('a, _) t, _) t
val create_matrix : int -> int -> 'a -> (('a, _) t, _) t
Iterators
val iter : ('a -> unit) -> ('a, [> `Read ]) t -> unit
val map : ('a -> 'b) -> ('a, [> `Read ]) t -> ('b, _) t
val iteri : (int -> 'a -> unit) -> ('a, [> `Read ]) t -> unit
val mapi : (int -> 'a -> 'b) -> ('a, [> `Read ]) t -> ('b, _) t
val modify : ('a -> 'a) -> ('a, [ `Read | `Write ]) t -> unit
val modifyi : (int -> 'a -> 'a) -> ('a, [ `Read | `Write ]) t -> unit
val fold_left : ('a -> 'b -> 'a) -> 'a -> ('b, [> `Read ]) t -> 'a
val fold_right : ('b -> 'a -> 'a) -> ('b, [> `Read ]) t -> 'a -> 'a
Operations on two arrays
val iter2 : ('a -> 'b -> unit) -> ('a, [> `Read ]) t -> ('b, [> `Read ]) t -> unit
val iter2i : (int -> 'a -> 'b -> unit) -> ('a, [> `Read ]) t -> ('b, [> `Read ]) t -> unit
Predicates
val for_all : ('a -> bool) -> ('a, [> `Read ]) t -> bool
val exists : ('a -> bool) -> ('a, [> `Read ]) t -> bool
val mem : 'a -> ('a, [> `Read ]) t -> bool
val memq : 'a -> ('a, [> `Read ]) t -> bool
val filter : ('a -> bool) -> ('a, [> `Read ]) t -> ('a, _) t
val filter_map : ('a -> 'b option) -> ('a, [> `Read ]) t -> ('b, _) t
val find_all : ('a -> bool) -> ('a, [> `Read ]) t -> ('a, _) t
val partition : ('a -> bool) -> ('a, [> `Read ]) t -> ('a, _) t * ('a, _) t
Array transformations
val rev : ('a, [> `Read ]) t -> ('a, _) t
val rev_in_place : ('a, [ `Read | `Write ]) t -> unit
val append : ('a, [> `Read ]) t -> ('a, [> `Read ]) t -> ('a, _) t
val concat : ('a, [> `Read ]) t list -> ('a, _) t
val sub : ('a, [> `Read ]) t -> int -> int -> ('a, _) t
val copy : ('a, [> `Read ]) t -> 'a array
val fill : ('a, [> `Write ]) t -> int -> int -> 'a -> unit
val blit : ('a, [> `Read ]) t -> int -> ('a, [> `Write ]) t -> int -> int -> unit
Conversions
val enum : ('a, [> `Read ]) t -> 'a BatEnum.t
val of_enum : 'a BatEnum.t -> ('a, _) t
val backwards : ('a, [> `Read ]) t -> 'a BatEnum.t
val of_backwards : 'a BatEnum.t -> ('a, _) t
val to_list : ('a, [> `Read ]) t -> 'a list
val split : ('a * 'b, [> `Read ]) t -> ('a, _) t * ('b, _) t
val of_list : 'a list -> ('a, _) t
Utilities
val sort : ('a -> 'a -> int) -> ('a, [> `Read | `Write ]) t -> unit
val stable_sort : ('a -> 'a -> int) -> ('a, [ `Read | `Write ]) t -> unit
val fast_sort : ('a -> 'a -> int) -> ('a, [ `Read | `Write ]) t -> unit
Boilerplate code
val print : ?first:string -> ?last:string -> ?sep:string -> ('a BatIO.output -> 'b -> unit) -> 'a BatIO.output -> ('b, [> `Read ]) t -> unit
val compare : 'a BatOrd.comp -> ('a, [> `Read ]) t BatOrd.comp
val ord : 'a BatOrd.ord -> ('a, [> `Read ]) t BatOrd.ord
val equal : 'a BatOrd.eq -> ('a, [> `Read ]) t BatOrd.eq
Override modules
module Exceptionless = BatArray.Cap.Exceptionless

Operations on BatArray.Cap without exceptions.

module Labels = BatArray.Cap.Labels

Operations on BatArray.Cap with labels.

include module type of struct include BatArray.Cap.Exceptionless end

Operations on BatArray.Cap without exceptions.

val find : ('a -> bool) -> ('a, [> `Read ]) BatArray.Cap.t -> 'a option
val findi : ('a -> bool) -> ('a, [> `Read ]) BatArray.Cap.t -> int option
OCaml

Innovation. Community. Security.