type
TypedDict
@Js
const class TypedDict : Obj, Dict
TypedDict wraps a dict that maps tags to statically typed fields. To use this API:
- Create subclass of TypedDict
- Annotate const instance fields with
@TypedTag
- Create constructor with Dict and it-block callback
- Optionally create convenience factory that calls
create
The following coercions are supported:
- Int field from Number tag
- Duration field from Number tag
- Bool field from Marker tag
Example:
const class ExampleRec : TypedDict { static new wrap(Dict d, |Str|? onErr := null) { create(ExampleRec#, d, onErr) } new make(Dict d, |This| f) : super(d) { f(this) } @TypedTag const Int limit := 99 @TypedTag const Duration timeout := 3sec }
constructors
make |
Sub constructor. |
---|
methods
create |
Factory to create for given type and dict to wrap. |
---|---|
each |
Iterate the wrapped dict tags |
eachWhile |
Iterate the wrapped dict tags until callback returns non-null |
get |
Get a tag from wrapped dict |
has |
Return if wrapped dict has given tag |
isEmpty |
Return if wrapped dict is empty |
meta |
Wrapped dict for this instance |
missing |
Return if wrapped dict is missing given tag |
trap |
Trap on the wrapped dict |
Slot Details
create
each
eachWhile
get
has
isEmpty
virtual override Bool isEmpty()
Return if wrapped dict is empty
make
new make(Dict meta)
Sub constructor.
meta
Dict meta()
Wrapped dict for this instance