Module pl.Map

A Map class.

> Map = require 'pl.Map'
> m = Map{one=1,two=2}
> m:update {three=3,four=4,two=20}
> = m == M{one=1,two=20,three=3,four=4}
true

Dependencies: pl.utils , pl.class , pl.tablex , pl.pretty

Functions

Map:iter () return an iterator over all key-value pairs.
Map:items () return a List of all key-value pairs, sorted by the keys.
Map:len () size of map.
Map:set (key, val) put a value into the map.
Map:get (key) get a value from the map.
Map:getvalues (keys) get a list of values indexed by a list of keys.
Map:update (table) update the map using key/value pairs from another table.

Fields

keys list of keys.
values list of values.


Functions

Map:iter ()
return an iterator over all key-value pairs.
Map:items ()
return a List of all key-value pairs, sorted by the keys.
Map:len ()
size of map. note: this is a relatively expensive operation!
Map:set (key, val)
put a value into the map.

Parameters:

  • key the key
  • val the value
Map:get (key)
get a value from the map.

Parameters:

  • key the key

Returns:

    the value, or nil if not found.
Map:getvalues (keys)
get a list of values indexed by a list of keys.

Parameters:

  • keys a list-like table of keys

Returns:

    a new list
Map:update (table)
update the map using key/value pairs from another table.

Parameters:

  • table

Fields

keys
list of keys.
values
list of values.
generated by LDoc 1.4.0