mirror of
https://github.com/wren-lang/wren.git
synced 2026-01-11 14:18:42 +01:00
Proposed additions to Map class docs. (#888)
The Map class documentation is missing a few details which I think should ideally be covered. The proposed changes should be self evident.
This commit is contained in:
@ -1,7 +1,15 @@
|
|||||||
^title Map Class
|
^title Map Class
|
||||||
|
|
||||||
|
Extends [Sequence](sequence.html).
|
||||||
|
|
||||||
An associative collection that maps keys to values. More details [here](../../maps.html).
|
An associative collection that maps keys to values. More details [here](../../maps.html).
|
||||||
|
|
||||||
|
## Static Method
|
||||||
|
|
||||||
|
### Map.**new**()
|
||||||
|
|
||||||
|
Creates a new empty map. Equivalent to `{}`.
|
||||||
|
|
||||||
## Methods
|
## Methods
|
||||||
|
|
||||||
### **clear**()
|
### **clear**()
|
||||||
@ -56,3 +64,22 @@ replaces the previous association.
|
|||||||
It is a runtime error if the key is not a [Bool](bool.html),
|
It is a runtime error if the key is not a [Bool](bool.html),
|
||||||
[Class](class.html), [Null](null.html), [Num](num.html), [Range](range.html),
|
[Class](class.html), [Null](null.html), [Num](num.html), [Range](range.html),
|
||||||
or [String](string.html).
|
or [String](string.html).
|
||||||
|
|
||||||
|
### **iterate**(iterator), **iteratorValue**(iterator)
|
||||||
|
|
||||||
|
Implements the [iterator protocol][] for iterating over the keys and values of a map at the same time.
|
||||||
|
|
||||||
|
[iterator protocol]: ../../control-flow.html#the-iterator-protocol
|
||||||
|
|
||||||
|
When a map (as opposed to its keys or values separately) is iterated over, each key/value pair is wrapped in a `MapEntry` object. `MapEntry` is a small helper class which has read-only `key` and `value` properties and a familiar `toString` representation.
|
||||||
|
|
||||||
|
<pre class="snippet">
|
||||||
|
var map = {"paul": "mccartney"}
|
||||||
|
for (entry in map) {
|
||||||
|
System.print(entry.type) // MapEntry
|
||||||
|
System.print(entry.key + " " + entry.value) // paul mccartney
|
||||||
|
System.print(entry) // paul:mccartney
|
||||||
|
}
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
All map entries will be iterated over, but may be in any order, and may even change between invocations of Wren.
|
||||||
|
|||||||
Reference in New Issue
Block a user