Class: SelfCanonMap

SelfCanonMap()

A version of CanonMap that is specialized for creating indexes: mapping an object's identifying attributes, specified by canonization, to the object itself.

Constructor

new SelfCanonMap()

Source:
Example
Take this data type Duck: { name: string, featherCount: number ).
Ducks are identified by their name, so we can use a SelfCanonMap both to store the canonical version of a Duck, and to look up a Duck knowing its name only:

const duckMap = new SelfCanonMap([{ name: 'Rodney', featherCount: 13217 }, { name: 'Ellis', featherCount: 11992 }], ({name}) => name)
duckMap.get({name: 'Ellis'}) // { name: 'Ellis', featherCount: 11992 }

Methods

add(val)

Adds the value to the SelfCanonMap. If any value collides with its canonization, that value will be overwritten.

Parameters:
Name Type Description
val T

The value to set.

Source:
Returns:

the SelfCanonMap object.

fill(vals)

Adds values to the SelfCanonMap. If any value collides with its canonization, that value will be overwritten.

Parameters:
Name Type Description
vals T

The values to add.

Source:
Returns:

the SelfCanonMap object.