Skip to content

Commit 6372160

Browse files
committed
Add Map.map examples.
1 parent a065f50 commit 6372160

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

lib/core/collections.toit

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3200,6 +3200,19 @@ class Map extends HashedInsertionOrderedCollection_:
32003200
32013201
The $block is invoked with two arguments for each entry in this instance:
32023202
the key and the value. The returned value becomes the new value for the key.
3203+
3204+
# Examples
3205+
```
3206+
map := { "a": 1, "b": 2 }
3207+
3208+
// Double the values. (Key is not used).
3209+
doubled := map.map: | _ value | value * 2
3210+
print doubled // => { "a": 2, "b": 4 }
3211+
3212+
// Prefix the values with the key.
3213+
prefixed := map.map: | key value | "$key-$value"
3214+
print prefixed // => { "a": "a-1", "b": "b-2" }
3215+
```
32033216
*/
32043217
map [block] -> Map:
32053218
result := Map

0 commit comments

Comments
 (0)