Skip to content

Commit

Permalink
Add Map.map examples.
Browse files Browse the repository at this point in the history
  • Loading branch information
floitsch committed Jan 30, 2025
1 parent a065f50 commit 6372160
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lib/core/collections.toit
Original file line number Diff line number Diff line change
Expand Up @@ -3200,6 +3200,19 @@ class Map extends HashedInsertionOrderedCollection_:
The $block is invoked with two arguments for each entry in this instance:
the key and the value. The returned value becomes the new value for the key.
# Examples
```
map := { "a": 1, "b": 2 }
// Double the values. (Key is not used).
doubled := map.map: | _ value | value * 2
print doubled // => { "a": 2, "b": 4 }
// Prefix the values with the key.
prefixed := map.map: | key value | "$key-$value"
print prefixed // => { "a": "a-1", "b": "b-2" }
```
*/
map [block] -> Map:
result := Map
Expand Down

0 comments on commit 6372160

Please sign in to comment.