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: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: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:

  • table tab

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.4.4 Last updated 2016-08-14 19:25:18