Class 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

Fields

pl.map.keys list of keys.
pl.map.values list of values.

Methods

pl.map:iter () return an iterator over all key-value pairs.
pl.map:items () return a List of all key-value pairs, sorted by the keys.
pl.map:setdefault (key, default) set a value in the map if it doesn't exist yet.
pl.map:len () size of map.
pl.map:set (key, val) put a value into the map.
pl.map:get (key) get a value from the map.
pl.map:getvalues (keys) get a list of values indexed by a list of keys.
pl.map:update (table) update the map using key/value pairs from another table.

Metamethods

pl.map:__eq (m) equality between maps.
pl.map:__tostring () string representation of a map.


Fields

pl.map.keys
list of keys.
pl.map.values
list of values.

Methods

pl.map:iter ()
return an iterator over all key-value pairs.
pl.map:items ()
return a List of all key-value pairs, sorted by the keys.
pl.map:setdefault (key, default)
set a value in the map if it doesn't exist yet.

Parameters:

  • key the key
  • default value to set

Returns:

    the value stored in the map (existing value, or the new value)
pl.map:len ()
size of map. note: this is a relatively expensive operation!
pl.map:set (key, val)
put a value into the map. This will remove the key if the value is nil

Parameters:

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

Parameters:

  • key the key

Returns:

    the value, or nil if not found.
pl.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
pl.map:update (table)
update the map using key/value pairs from another table.

Parameters:

Metamethods

pl.map:__eq (m)
equality between maps.

Parameters:

  • m Map another map.
pl.map:__tostring ()
string representation of a map.
generated by LDoc 1.5.0