Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Map.map examples. #2704

Merged
merged 1 commit into from
Jan 31, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading