From 79000a320e6902bfb55ebe353fe1c15e59e940ad Mon Sep 17 00:00:00 2001 From: PureFox48 <64583745+PureFox48@users.noreply.github.com> Date: Sun, 31 Jan 2021 05:22:54 +0000 Subject: [PATCH] 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. --- doc/site/modules/core/map.markdown | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/doc/site/modules/core/map.markdown b/doc/site/modules/core/map.markdown index e581e3fc..c2756f93 100644 --- a/doc/site/modules/core/map.markdown +++ b/doc/site/modules/core/map.markdown @@ -1,7 +1,15 @@ ^title Map Class +Extends [Sequence](sequence.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 ### **clear**() @@ -56,3 +64,22 @@ replaces the previous association. 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), 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. + +
+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
+}
+
+
+All map entries will be iterated over, but may be in any order, and may even change between invocations of Wren.