Skip to content

Record[...Ts]

Stores an immutable sequence of positional items and symbol-keyed items.

Records keep their items in order, and a key may repeat. A lookup finds the latest value for a key. Keys are read by indexing, not as fields:

let r = record name: Alice age: 30
assert_eq $r[:name:] Alice

A variadic capture such as ...rest binds a record of the remaining arguments. To produce a changed record, spread the old record into a new one:

let updated = record ...old status: ready

Inherits from: Iterable[Tuple[Sym | Int, Value]]

Implements: Index[{...Ts}], Spread[{...Ts}], Unpack[{...Ts}]

Constructor

Record source

Builds a record from one spreadable source of key-value pairs.

let r = Record {name: Alice, age: 30}

Integer keys counting up from 0 become positional items, as when spreading a dict.

The lowercase record factory instead builds a record from its arguments.

let r = record first second name: Alice

Errors

Raises TypeError for any other key that is not a symbol.

Methods

(iter)()

Iterates record items as [key, value] pairs in order. A positional item's key is its position.

(unpack)()

Unpacks record items by position and symbol.

get[D = nil] key … -> (Value | D)

Gets the value for a symbol or position, with an optional default.

Parameters

NameTypeDescription
key (Int | Sym)
:default? D
:else? (() -> D)

len() -> Int

Number of items, counting each instance of a repeated key.