Map#

class Map(_Map__tree: Option[MapTreeLeaf[_Key, _Value]] | None = None)#

The immutable map class.

for_all(predicate: Callable[[_Key, _Value], bool]) bool#

Test all elements in map.

Returns true if the given predicate returns true for all of the bindings in the map.

Parameters:

predicate – The function to test the input elements.

Returns:

True if the predicate evaluates to true for all of the bindings in the map.

items() a set-like object providing a view on D's items#
map(mapping: Callable[[_Key, _Value], _Result]) Map[_Key, _Result]#

Map the mapping.

Builds a new collection whose elements are the results of applying the given function to each of the elements of the collection. The key passed to the function indicates the key of element being transformed.

Parameters:

mapping – The function to transform the key/value pairs

Returns:

The resulting map of keys and transformed values.

static of_block(lst: Block[tuple[_Key, _Value]]) Map[_Key, _Value]#

Generate map from list.

Returns:

The new map.

static of_list(lst: list[tuple[_Key_, _Result]]) Map[_Key_, _Result]#

Generate map from list.

Returns:

The new map.

static of_seq(sequence: Iterable[tuple[_Key_, _Result]]) Map[_Key_, _Result]#

Generate map from sequence.

Generates a new map from an iterable of key/value tuples. This is an alias for Map.create.

Returns:

The new map.

to_seq() Iterable[tuple[_Key, _Value]]#

Convert to sequence.

Returns:

Sequence of key, value tuples.

add(table: Map[_Key, _Value], key: _Key, value: _Value) Map[_Key, _Value]#

Add key with value to map.

Returns a new map with the binding added to the given map. If a binding with the given key already exists in the input map, the existing binding is replaced by the new binding in the result map.

Parameters:
  • table – The input map.

  • key – The input key.

  • value – The input value.

Returns:

A partially applied add function that takes the input map and returns the output map.

change(table: Map[_Key, _Value], key: _Key, fn: Callable[[Option[_Value]], Option[_Value]]) Map[_Key, _Value]#

Change element in map.

Returns a new map with the value stored under key changed according to f.

Parameters:
  • key – The input key.

  • fn – The change function.

  • table – The input table.

Returns:

The input key.

count(table: Map[Any, Any]) int#

Return the number of bindings in the map.

exists(table: Map[_Key, _Value], predicate: Callable[[_Key, _Value], bool]) bool#

Test if element exists in map.

Returns true if the given predicate returns true for one of the bindings in the map.

Parameters:
  • table – The input map.

  • predicate – The function to test the input elements.

Returns:

Partially applied function that takes a map table and returns true if the predicate returns true for one of the key/value pairs.

find(table: Map[_Key, _Value], key: _Key) _Value#

Find element with key in map.

Lookup an element in the map, raising KeyNotFoundException if no binding exists in the map.

Parameters:
  • key – The key to find.

  • table – The map to find the key in.

is_empty(table: Map[Any, Any]) bool#

Is the map empty?

Parameters:

table – The input map.

Returns:

True if the map is empty.

of(**args: _Value) Map[str, _Value]#

Create map from arguments.

remove(table: Map[_Key, _Value], key: _Key) Map[_Key, _Value]#

Remove element from map.

Removes an element from the domain of the map. No exception is raised if the element is not present.

Parameters:
  • key – The key to remove.

  • table – The table to remove the key from.

Returns:

The resulting map.

try_find(table: Map[_Key, _Value], key: _Key) Option[_Value]#

Try to find element with key in map.

Lookup an element in the map, returning a Some value if the element is in the domain of the map and Nothing if not.

Parameters:
  • table – The input map.

  • key – The input key.

Returns:

A partially applied try_find function that takes a map instance and returns the result.

try_pick(table: Map[_Key, _Value], chooser: Callable[[_Key, _Value], Option[_Result]]) Option[_Result]#

Pick element in map.

Searches the map looking for the first element where the given function returns a Some value.

Parameters:
  • table – The input map.

  • chooser – The function to generate options from the key/value pairs.

Returns:

Partially applied try_pick function that takes the input map and returns the first result.