package batteries

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Module BatArray.CapSource

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.

Only the capability-specific functions are documented here. See the complete Array module for the documentation of other functions.

Sourcetype ('a, 'b) 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

Sourceval length : ('a, [> ]) t -> int
Sourceval get : ('a, [> `Read ]) t -> int -> 'a
Sourceval set : ('a, [> `Write ]) t -> int -> 'a -> unit

Constructors

Sourceval make : int -> 'a -> ('a, _) t
Sourceval create : int -> 'a -> ('a, _) t
Sourceval 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
Sourceval 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.

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

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

Drop to read-only permissions.

This operation involves no copying.

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

Drop to write-only permissions.

This operation involves no copying.

Sourceval init : int -> (int -> 'a) -> ('a, _) t
Sourceval make_matrix : int -> int -> 'a -> (('a, _) t, _) t
Sourceval create_matrix : int -> int -> 'a -> (('a, _) t, _) t

Iterators

Sourceval iter : ('a -> unit) -> ('a, [> `Read ]) t -> unit
Sourceval map : ('a -> 'b) -> ('a, [> `Read ]) t -> ('b, _) t
Sourceval iteri : (int -> 'a -> unit) -> ('a, [> `Read ]) t -> unit
Sourceval mapi : (int -> 'a -> 'b) -> ('a, [> `Read ]) t -> ('b, _) t
Sourceval modify : ('a -> 'a) -> ('a, [ `Read | `Write ]) t -> unit
Sourceval modifyi : (int -> 'a -> 'a) -> ('a, [ `Read | `Write ]) t -> unit
Sourceval fold_left : ('a -> 'b -> 'a) -> 'a -> ('b, [> `Read ]) t -> 'a
Sourceval fold : ('a -> 'b -> 'a) -> 'a -> ('b, [> `Read ]) t -> 'a
Sourceval fold_right : ('b -> 'a -> 'a) -> ('b, [> `Read ]) t -> 'a -> 'a
Sourceval fold_while : ('acc -> 'a -> bool) -> ('acc -> 'a -> 'acc) -> 'acc -> ('a, [> `Read ]) t -> 'acc * int

Operations on two arrays

Sourceval iter2 : ('a -> 'b -> unit) -> ('a, [> `Read ]) t -> ('b, [> `Read ]) t -> unit
Sourceval iter2i : (int -> 'a -> 'b -> unit) -> ('a, [> `Read ]) t -> ('b, [> `Read ]) t -> unit

Predicates

Sourceval for_all : ('a -> bool) -> ('a, [> `Read ]) t -> bool
Sourceval exists : ('a -> bool) -> ('a, [> `Read ]) t -> bool
Sourceval find : ('a -> bool) -> ('a, [> `Read ]) t -> 'a
Sourceval find_opt : ('a -> bool) -> ('a, [> `Read ]) t -> 'a option
Sourceval find_map : ('a -> 'b option) -> ('a, [> `Read ]) t -> 'b option
Sourceval mem : 'a -> ('a, [> `Read ]) t -> bool
Sourceval memq : 'a -> ('a, [> `Read ]) t -> bool
Sourceval findi : ('a -> bool) -> ('a, [> `Read ]) t -> int
Sourceval filter : ('a -> bool) -> ('a, [> `Read ]) t -> ('a, _) t
Sourceval filter_map : ('a -> 'b option) -> ('a, [> `Read ]) t -> ('b, _) t
Sourceval count_matching : ('a -> bool) -> ('a, [> `Read ]) t -> int
Sourceval find_all : ('a -> bool) -> ('a, [> `Read ]) t -> ('a, _) t
Sourceval partition : ('a -> bool) -> ('a, [> `Read ]) t -> ('a, _) t * ('a, _) t

Array transformations

Sourceval rev : ('a, [> `Read ]) t -> ('a, _) t
Sourceval rev_in_place : ('a, [ `Read | `Write ]) t -> unit
Sourceval append : ('a, [> `Read ]) t -> ('a, [> `Read ]) t -> ('a, _) t
Sourceval concat : ('a, [> `Read ]) t list -> ('a, _) t
Sourceval sub : ('a, [> `Read ]) t -> int -> int -> ('a, _) t
Sourceval copy : ('a, [> `Read ]) t -> 'a array
Sourceval fill : ('a, [> `Write ]) t -> int -> int -> 'a -> unit
Sourceval blit : ('a, [> `Read ]) t -> int -> ('a, [> `Write ]) t -> int -> int -> unit

Conversions

Sourceval enum : ('a, [> `Read ]) t -> 'a BatEnum.t
Sourceval of_enum : 'a BatEnum.t -> ('a, _) t
Sourceval backwards : ('a, [> `Read ]) t -> 'a BatEnum.t
Sourceval of_backwards : 'a BatEnum.t -> ('a, _) t
Sourceval to_list : ('a, [> `Read ]) t -> 'a list
Sourceval split : ('a * 'b, [> `Read ]) t -> ('a, _) t * ('b, _) t
Sourceval combine : ('a, [> `Read ]) t -> ('b, [> `Read ]) t -> ('a * 'b, [> `Read ]) t
Sourceval pivot_split : 'a BatOrd.ord -> ('a, [> `Read ]) t -> 'a -> int * int
Sourceval of_list : 'a list -> ('a, _) t

Utilities

Sourceval sort : ('a -> 'a -> int) -> ('a, [> `Read | `Write ]) t -> unit
Sourceval stable_sort : ('a -> 'a -> int) -> ('a, [ `Read | `Write ]) t -> unit
Sourceval fast_sort : ('a -> 'a -> int) -> ('a, [ `Read | `Write ]) t -> unit

Boilerplate code

Sourceval print : ?first:string -> ?last:string -> ?sep:string -> ('a BatIO.output -> 'b -> unit) -> 'a BatIO.output -> ('b, [> `Read ]) t -> unit
Sourceval compare : 'a BatOrd.comp -> ('a, [> `Read ]) t BatOrd.comp
Sourceval ord : 'a BatOrd.ord -> ('a, [> `Read ]) t BatOrd.ord
Sourceval equal : 'a BatOrd.eq -> ('a, [> `Read ]) t BatOrd.eq

Override modules

Sourcemodule Exceptionless : sig ... end

Operations on BatArray.Cap without exceptions.

Sourcemodule Labels : sig ... end

Operations on BatArray.Cap with labels.

OCaml

Innovation. Community. Security.