Axle v0.22.0
Package

std/core/util

std/core/util — small utilities (Optional / Pair / OptionalCell).

Optional<T>, Pair<A, B> and OptionalCell<T> are implementable in pure Axle
without any FFI: they're tiny generic classes whose methods are
straight assignments / branches over their fields. The richer
Optional::map(fn) / filter(fn) variants require lambda
support, so this module exposes the no-lambda subset.

C class Pair<A, B>

An immutable two-value tuple — first / second are set once at
construction and read back as plain fields.

Constructors

TypeMethod and description
constructor(first : A, second : B) Pair holding first and second.

Method detail

#constructor

constructor(first : A, second : B)

Pair holding first and second.

Parameters
first value stored in the first field
second value stored in the second field

C class Optional<T>

Minimal surface: the heavy map / filter / ifPresent
methods require lambdas (deferred). orElse(fallback) is the
only safe accessor — a typed get() throws NoSuchElementException
depends on the throwing-i32-return gap (api/stdlib.md #9).

Constructors

TypeMethod and description
constructor(present : bool, v : T) Low-level constructor: present flags whether v is a real value.
When present is false, v is an ignored placeholder.

Method detail

#constructor

constructor(present : bool, v : T)

Low-level constructor: present flags whether v is a real value.
When present is false, v is an ignored placeholder.

Parameters
present true if v is a real value, false if absent
v the held value; ignored placeholder when present is false

Methods

TypeMethod and description
bool
isPresent(self) : bool true when this holds a value.
bool
isEmpty(self) : bool true when this is empty (absent value).
T
orElse(self, fallback : T) : T The contained value if present, otherwise fallback.

Method detail

#isPresent

isPresent(self) : bool

true when this holds a value.

#isEmpty

isEmpty(self) : bool

true when this is empty (absent value).

#orElse

orElse(self, fallback : T) : T

The contained value if present, otherwise fallback.

Parameters
fallback value returned when this Optional is empty
Returns the contained value when present, otherwise fallback

C class OptionalCell<T>

A cell that may be empty, kept in an Optional<T> of its own: a generic
class naming another generic class on its type parameter.
OptionalCell<i32> holds an Optional<i32>, built by its constructor and
read through its methods.

Constructors

TypeMethod and description
constructor(present : bool, v : T) Cell holding v when present, empty otherwise.

Method detail

#constructor

constructor(present : bool, v : T)

Cell holding v when present, empty otherwise.

Parameters
present true if v is a real value, false for an empty cell
v the held value; ignored placeholder when present is false

Methods

TypeMethod and description
bool
isPresent(self) : bool true when the cell holds a value.
T
orElse(self, fallback : T) : T The held value if present, otherwise fallback.

Method detail

#isPresent

isPresent(self) : bool

true when the cell holds a value.

#orElse

orElse(self, fallback : T) : T

The held value if present, otherwise fallback.

Parameters
fallback value returned when the cell is empty
Returns the held value when present, otherwise fallback