Skip to main content

core/Types

Common types used throughout the core package.

Example usage:

import { type Result; type Iter } "mo:core/Types";

// Result for error handling
let result : Result<Int, Text> = #ok(42);

// Iterator for sequences
let iter : Iter<Nat> = { next = func() { ?1 } };

Type Blob

type Blob = Prim.Types.Blob

Type Bool

type Bool = Prim.Types.Bool

Type Char

type Char = Prim.Types.Char

Type Error

type Error = Prim.Types.Error

Type ErrorCode

type ErrorCode = Prim.ErrorCode

Type Float

type Float = Prim.Types.Float

Type Int

type Int = Prim.Types.Int

Type Int8

type Int8 = Prim.Types.Int8

Type Int16

type Int16 = Prim.Types.Int16

Type Int32

type Int32 = Prim.Types.Int32

Type Int64

type Int64 = Prim.Types.Int64

Type Nat

type Nat = Prim.Types.Nat

Type Nat8

type Nat8 = Prim.Types.Nat8

Type Nat16

type Nat16 = Prim.Types.Nat16

Type Nat32

type Nat32 = Prim.Types.Nat32

Type Nat64

type Nat64 = Prim.Types.Nat64

Type Principal

type Principal = Prim.Types.Principal

Type Region

type Region = Prim.Types.Region

Type Text

type Text = Prim.Types.Text

Type Hash

type Hash = Nat32

Type Iter

type Iter<T> = { next : () -> ?T }

Type Order

type Order = {#less; #equal; #greater}

Type Result

type Result<T, E> = {#ok : T; #err : E}

Type Pattern

type Pattern = {#char : Char; #text : Text; #predicate : (Char -> Bool)}

Type Time

type Time = Int

Type Duration

type Duration = {#days : Nat; #hours : Nat; #minutes : Nat; #seconds : Nat; #milliseconds : Nat; #nanoseconds : Nat}

Type TimerId

type TimerId = Nat

Type List

type List<T> = { var blocks : [var [var ?T]]; var blockIndex : Nat; var elementIndex : Nat }

Module Queue

module Queue

Type Queue

type Queue<T> = { var front : ?Node<T>; var back : ?Node<T>; var size : Nat }

Type Node

type Node<T> = { value : T; var next : ?Node<T>; var previous : ?Node<T> }

Type Queue

type Queue<T> = Queue.Queue<T>

Module Set

module Set

Type Node

type Node<T> = {#leaf : Leaf<T>; #internal : Internal<T>}

Type Data

type Data<T> = { elements : [var ?T]; var count : Nat }

Type Internal

type Internal<T> = { data : Data<T>; children : [var ?Node<T>] }

Type Leaf

type Leaf<T> = { data : Data<T> }

Type Set

type Set<T> = { var root : Node<T>; var size : Nat }

Type Set

type Set<T> = Set.Set<T>

Module Map

module Map

Type Node

type Node<K, V> = {#leaf : Leaf<K, V>; #internal : Internal<K, V>}

Type Data

type Data<K, V> = { kvs : [var ?(K, V)]; var count : Nat }

Type Internal

type Internal<K, V> = { data : Data<K, V>; children : [var ?Node<K, V>] }

Type Leaf

type Leaf<K, V> = { data : Data<K, V> }

Type Map

type Map<K, V> = { var root : Node<K, V>; var size : Nat }

Type Map

type Map<K, V> = Map.Map<K, V>

Module Stack

module Stack

Type Stack

type Stack<T> = { var top : Pure.List<T>; var size : Nat }

Type Stack

type Stack<T> = Stack.Stack<T>

Module Pure

module Pure

Type List

type List<T> = ?(T, List<T>)

Module Map

module Map

Type Map

type Map<K, V> = { size : Nat; root : Tree<K, V> }

Type Tree

type Tree<K, V> = {#red : (Tree<K, V>, K, V, Tree<K, V>); #black : (Tree<K, V>, K, V, Tree<K, V>); #leaf}

Type Map

type Map<K, V> = Map.Map<K, V>

Type Queue

type Queue<T> = (List<T>, Nat, List<T>)

Module Set

module Set

Type Tree

type Tree<T> = {#red : (Tree<T>, T, Tree<T>); #black : (Tree<T>, T, Tree<T>); #leaf}

Type Set

type Set<T> = { size : Nat; root : Tree<T> }

Type Set

type Set<T> = Set.Set<T>