Skip to content

Documentation / @ripl/charts / createKeyedLookup

Function: createKeyedLookup() ​

createKeyedLookup<TValue, TKey>(values, getKey): (key) => TValue | undefined

Defined in: charts/src/core/data.ts:83

Builds a key → value lookup with Array.prototype.find semantics over a key comparison: the earliest match wins for a duplicated key, and an unknown key resolves to undefined.

Type Parameters ​

Type ParameterDescription
TValueThe array's element type.
TKeyThe key type the values are looked up by.

Parameters ​

ParameterTypeDescription
valuesreadonly TValue[]The array to index, in order.
getKey(value) => TKeyResolves a value's lookup key.

Returns ​

A function resolving a key to its first matching value, or undefined when absent.

(key) => TValue | undefined