Struct[S @ {...}]
A mutable sequence of positional and symbol-keyed items, whose plain names are
its keyed items. A struct has no methods of its own, so s.name reads the item
keyed :name: and s.name = value replaces or adds it. Calling s.name args
calls the item.
Each symbol key appears at most once. Positional items are read and replaced
through indexing, as in s[0]. Class methods such as
get take the struct as their first argument, so they
can't collide with an item.
The schema S types each item, so the type checker reports reading or
writing a name the schema lacks.
Inherits from: BaseStruct[S]
Implements: Assign[S]
Constructor
Struct source
Builds a struct from one spreadable source of key-value pairs.
Integer keys counting up from 0 become positional items, as when
spreading a dict.
The lowercase struct factory instead builds a struct from
its arguments.
Parameters
| Name | Type | Description |
|---|---|---|
source |
Spread[S] |
Errors
| Exception | Condition |
|---|---|
TypeError |
Another key is not a symbol |
ValueError |
A symbol key is repeated |
Methods
(assign)[K] key value
Replaces the item at a position or key. A new symbol key adds an item.
Parameters
| Name | Type | Description |
|---|---|---|
key |
K |
|
value |
AssignItem[S, K] |
Errors
Raises IndexError for a position with no item.
(set)[K] key value
Replaces the item a name keys, or adds one, as in s.name = value.
Parameters
| Name | Type | Description |
|---|---|---|
key |
K |
|
value |
AssignItem[S, K] |