base.DefaultMap(factory, iterableopt)

Subclass of {Map} similar to Python's defaultdict.

First argument is a factory function that will create a new default value for the key if not already present in the container.

The factory function may take arguments. When getWithArguments is used, those arguments will be passed to the factory.

new DefaultMap(factory, iterableopt)

Parameters:
Name Type Attributes Description
factory function

Function that creates a new default value if a requested key is not present.

iterable Iterable <optional>

Passed to {Map} super().

Extends

  • Map

Methods

get(key) → {object}

Parameters:
Name Type Description
key object

The key of the element to return from this instance.

Returns:
object -

The value associated with the key, perhaps newly created.

getWithArguments(key, …args) → {object}

Variant of Map.prototype.get() that passes args to the factory.

Parameters:
Name Type Attributes Description
key object

The key of the element to return from this instance.

args object <repeatable>

Extra arguments passed to the factory function if it is called.

Returns:
object -

The value associated with the key, perhaps newly created.