BatArray.Cap

# Module BatArray.Cap

    module Cap: sig .. 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.

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

    type ('a, [< `Read | `Write ]) t

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, [< `Read | `Write ]) t -> int

    val get : ('a, [< `Read | `Write > `Read ]) t -> int -> 'a

    val set : ('a, [< `Read | `Write > `Write ]) t -> int -> 'a -> unit

    val make : int -> 'a -> ('a, [< `Read | `Write ]) t

###### Constructors

    val create : int -> 'a -> ('a, [< `Read | `Write ]) t

    val of_array : 'a array -> ('a, [< `Read | `Write ]) 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 | `Write > `Read ]) t ->
           ('a, [ `Read ]) t

Drop to read-only permissions.

This operation involves no copying.

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

Drop to write-only permissions.

This operation involves no copying.

    val init : int -> (int -> 'a) -> ('a, [< `Read | `Write ]) t

    val make_matrix : int ->
           int ->
           'a ->
           (('a, [< `Read | `Write ]) t, [< `Read | `Write ])
           t

    val create_matrix : int ->
           int ->
           'a ->
           (('a, [< `Read | `Write ]) t, [< `Read | `Write ])
           t

    val iter : ('a -> unit) -> ('a, [< `Read | `Write > `Read ]) t -> unit

###### Iterators

    val map : ('a -> 'b) ->
           ('a, [< `Read | `Write > `Read ]) t ->
           ('b, [< `Read | `Write ]) t

    val iteri : (int -> 'a -> unit) ->
           ('a, [< `Read | `Write > `Read ]) t -> unit

    val mapi : (int -> 'a -> 'b) ->
           ('a, [< `Read | `Write > `Read ]) t ->
           ('b, [< `Read | `Write ]) 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 | `Write > `Read ]) t -> 'a

    val fold_right : ('a -> 'b -> 'b) ->
           ('a, [< `Read | `Write > `Read ]) t -> 'b -> 'b

    val iter2 : ('a -> 'b -> unit) ->
           ('a, [< `Read | `Write > `Read ]) t ->
           ('b, [< `Read | `Write > `Read ]) t -> unit

###### Operations on two arrays

    val iter2i : (int -> 'a -> 'b -> unit) ->
           ('a, [< `Read | `Write > `Read ]) t ->
           ('b, [< `Read | `Write > `Read ]) t -> unit

    val for_all : ('a -> bool) -> ('a, [< `Read | `Write > `Read ]) t -> bool

###### Predicates

    val exists : ('a -> bool) -> ('a, [< `Read | `Write > `Read ]) t -> bool

    val find : ('a -> bool) -> ('a, [< `Read | `Write > `Read ]) t -> 'a

    val mem : 'a -> ('a, [< `Read | `Write > `Read ]) t -> bool

    val memq : 'a -> ('a, [< `Read | `Write > `Read ]) t -> bool

    val findi : ('a -> bool) -> ('a, [< `Read | `Write > `Read ]) t -> int

    val filter : ('a -> bool) ->
           ('a, [< `Read | `Write > `Read ]) t ->
           ('a, [< `Read | `Write ]) t

    val filter_map : ('a -> 'b option) ->
           ('a, [< `Read | `Write > `Read ]) t ->
           ('b, [< `Read | `Write ]) t

    val find_all : ('a -> bool) ->
           ('a, [< `Read | `Write > `Read ]) t ->
           ('a, [< `Read | `Write ]) t

    val partition : ('a -> bool) ->
           ('a, [< `Read | `Write > `Read ]) t ->
           ('a, [< `Read | `Write ]) t *
           ('a, [< `Read | `Write ]) t

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

###### Array transformations

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

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

    val concat : ('a, [< `Read | `Write > `Read ]) t list ->
           ('a, [< `Read | `Write ]) t

    val sub : ('a, [< `Read | `Write > `Read ]) t ->
           int -> int -> ('a, [< `Read | `Write ]) t

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

    val fill : ('a, [< `Read | `Write > `Write ]) t -> int -> int -> 'a -> unit

    val blit : ('a, [< `Read | `Write > `Read ]) t ->
           int ->
           ('a, [< `Read | `Write > `Write ]) t -> int -> int -> unit

###### Conversions

    val enum : ('a, [< `Read | `Write > `Read ]) t -> 'a BatEnum.t

    val of_enum : 'a BatEnum.t -> ('a, [< `Read | `Write ]) t

    val backwards : ('a, [< `Read | `Write > `Read ]) t -> 'a BatEnum.t

    val of_backwards : 'a BatEnum.t -> ('a, [< `Read | `Write ]) t

    val to_list : ('a, [< `Read | `Write > `Read ]) t -> 'a list

    val of_list : 'a list -> ('a, [< `Read | `Write ]) t

    val make_compare : ('a -> 'a -> int) ->
           ('a, [< `Read | `Write > `Read ]) t ->
           ('a, [< `Read | `Write > `Read ]) t -> int

###### 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

Printing

    val print : ?first:string ->
           ?last:string ->
           ?sep:string ->
           ('a BatIO.output -> 'b -> unit) ->
           'a BatIO.output -> ('b, [< `Read | `Write > `Read ]) t -> unit

    val sprint : ?first:string ->
           ?last:string ->
           ?sep:string ->
           ('a BatIO.output -> 'b -> unit) ->
           ('b, [< `Read | `Write > `Read ]) t -> string

###### Override modules

    module Exceptionless: sig .. end

Operations on `BatArray.Cap` without exceptions.

    module Labels: sig .. end

Operations on `BatArray.Cap` with labels.