Skip to main content

LazyCollection<K, V>

A lazy reactive collection, whose values are computed only when queried.

A LazyCollection is a reactive collection of entries that associate keys to values where the entries are computed on-demand in response to queries. Once an entry has been computed, later queries will not need to recompute it, unless it's dependencies have changed.

Extends

Type Parameters

Type ParameterDescription
K extends JsonType of keys.
V extends JsonType of values.

Methods

getArray()

getArray(key): V & DepSafe[]

Get (and potentially compute) all values associated to key.

Parameters

ParameterTypeDescription
keyKThe key to query.

Returns

V & DepSafe[]

The values associated to key.


getUnique()

getUnique(key, _default?): V & DepSafe

Get (and potentially compute) the single value associated to key.

For collections that do not use the generality of associating multiple values to a key, getUnique saves some boilerplate over getArray.

Parameters

ParameterTypeDescription
keyKThe key to query.
_default?{ ifMany: V; ifNone: V; }
_default.ifMany?VDefault value for the case where multiple values are associated to the given key
_default.ifNone?VDefault value for the case where zero values are associated to the given key

Returns

V & DepSafe

The value associated to key.

Throws

SkipNonUniqueValueError if key is associated to either zero or multiple values and no suitable default is provided.