The Permissioned
module gives the ability to restrict permissions on an array, so
you can give a function read-only access to an array, create an immutable array, etc.
The meaning of the 'perms
parameter is as usual (see the Perms
module for more
details) with the non-obvious difference that you don't need any permissions to
extract the length of an array. This was done for simplicity because some
information about the length of an array can leak out even if you only have write
permissions since you can catch out-of-bounds errors.
of_array_id
and to_array_id
return the same underlying array. On the other
hand, to_array
(inherited from Container.S1_permissions
below) makes a copy.
To create a new (possibly immutable) copy of an array a
, use copy (of_array_id
a)
. More generally, any function that takes a (possibly mutable) t
can be called
on an array by calling of_array_id
on it first.
There is a conceptual type equality between 'a Array.t
and
('a, read_write) Array.Permissioned.t
. The reason for not exposing this as an
actual type equality is that we also want:
'a Array.t = 'a array
for interoperability with code which
does not use Core.('a, 'perms) Array.Permissioned.t
to be abstract, so that the
permission phantom type will have an effect.Since we don't control the definition of 'a array
, this would require a type
('a, 'perms) Array.Permissioned.t
which is abstract, except that
('a, read_write) Array.Permissioned.t
is concrete, which is not possible.
to_sequence_immutable t
converts t
to a sequence. Unlike to_sequence
,
to_sequence_immutable
does not need to copy t
since it is immutable.
Returns true
if and only if there exists an element for which the provided
function evaluates to true
. This is a short-circuiting operation.
Returns true
if and only if the provided function evaluates to true
for all
elements. This is a short-circuiting operation.
Returns the sum of f i
for i in the container
Returns a min (resp max) element from the collection using the provided cmp
function. In case of a tie, the first element encountered while traversing the
collection is returned. The implementation uses fold
so it has the same complexity
as fold
. Returns None
iff the collection is empty.
These functions are in Container.S1_permissions
, but they are re-exposed here so
that their types can be changed to make them more permissive (see comment above).
counterparts of regular array functions above