Skip to main content

VarArray

Reference for mo:core/VarArray in the core library.

VarArray provides trusted constructors and transformations for mutable arrays. The helpers preserve size in contracts, but callers still need ordinary array permissions and bounds facts when reading or writing elements.

Import

mo:core/VarArray

Status

  • Runtime module

Public API

Functions

repeat<T>(item : T, size : Nat) : [var T]

Constructs a mutable array from repeated values or an index function.

Contract

ensures result.size() == size;
ensures forall<Nat>(pure func (i : Nat) : Bool = i < result.size() ==> result[i] == item);

Use when: code or specifications need this operation with the documented contract.

tabulate<T>(size : Nat, generator : Nat -> T) : [var T]

Constructs a mutable array from repeated values or an index function.

Contract

ensures result.size() == size;

Use when: code or specifications need this operation with the documented contract.

map<A, B>(array : [var A], f : A -> B) : [var B]

Transforms the contained values with the supplied function while preserving the documented shape.

Contract

ensures result.size() == array.size();

Use when: code or specifications need this operation with the documented contract.

Summary

  • Runtime module under mo:core/VarArray.
  • Exposes 3 public functions.