From 826d30634901328a5481aad29f69f8e4e021fc35 Mon Sep 17 00:00:00 2001 From: Netta Schwarz Date: Mon, 29 Dec 2025 14:19:36 -0800 Subject: [PATCH 1/2] Add README.md file for update-all --- .../concepts/map/terms/update-all/README.md | 0 .../map/terms/update-all/update-all.md | 55 +++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 content/dart/concepts/map/terms/update-all/README.md create mode 100644 content/dart/concepts/map/terms/update-all/update-all.md diff --git a/content/dart/concepts/map/terms/update-all/README.md b/content/dart/concepts/map/terms/update-all/README.md new file mode 100644 index 00000000000..e69de29bb2d diff --git a/content/dart/concepts/map/terms/update-all/update-all.md b/content/dart/concepts/map/terms/update-all/update-all.md new file mode 100644 index 00000000000..49fe129ef6d --- /dev/null +++ b/content/dart/concepts/map/terms/update-all/update-all.md @@ -0,0 +1,55 @@ +--- +Title: '.updateAll()' +Description: 'Updates all values in a map by applying a function to each key-value pair.' +Subjects: + - 'Computer Science' + - 'Code Foundations' +Tags: + - 'Dart' + - 'Methods' + - 'Map' +CatalogContent: + - 'learn-dart' + - 'paths/computer-science' +--- + +The **`.updateAll()`** method in Dart updates all values in a map by applying a specified function to each key-value pair. The function receives both the key and its current value, and returns the new value that will replace the existing one. + +## Syntax + +```dart +map.updateAll((key, value) => newValue) +``` + +- `map`: The map to be updated. +- `key`: The key in each key-value pair. +- `value`: The current value associated with the key. +- `newValue`: The new value to replace the current value. + +## Example + +In the following example, the `.updateAll()` method is used to increase all scores by 10: + +```dart +void main() { + Map scores = { + 'Alice': 80, + 'Bob': 90, + 'Charlie': 85 + }; + + print('Original scores: $scores'); + + // Increase all scores by 10 + scores.updateAll((name, score) => score + 10); + + print('Updated scores: $scores'); +} +``` + +The above code produces the following output: + +```shell +Original scores: {Alice: 80, Bob: 90, Charlie: 85} +Updated scores: {Alice: 90, Bob: 100, Charlie: 95} +``` \ No newline at end of file From 679d4a811e042ac869189673e8c1e90a7bd56b11 Mon Sep 17 00:00:00 2001 From: Mamta Wardhani Date: Thu, 1 Jan 2026 13:25:02 +0530 Subject: [PATCH 2/2] Enhance documentation for the updateAll method Clarified parameters and return value for the updateAll method. Updated example to better illustrate its usage. --- .../map/terms/update-all/update-all.md | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/content/dart/concepts/map/terms/update-all/update-all.md b/content/dart/concepts/map/terms/update-all/update-all.md index 49fe129ef6d..f9862d5efda 100644 --- a/content/dart/concepts/map/terms/update-all/update-all.md +++ b/content/dart/concepts/map/terms/update-all/update-all.md @@ -17,18 +17,26 @@ The **`.updateAll()`** method in Dart updates all values in a map by applying a ## Syntax -```dart +```pseudo map.updateAll((key, value) => newValue) ``` -- `map`: The map to be updated. -- `key`: The key in each key-value pair. +**Parameters:** + +A function that takes two arguments: + +- `key`: The current key in the map. - `value`: The current value associated with the key. -- `newValue`: The new value to replace the current value. + +The function must return the new value to replace the existing one. + +**Return value:** + +Returns `void`. The map is modified in place. ## Example -In the following example, the `.updateAll()` method is used to increase all scores by 10: +In the following example, the `.updateAll()` method increases every score in the map by 10 using a transformation function: ```dart void main() { @@ -37,12 +45,12 @@ void main() { 'Bob': 90, 'Charlie': 85 }; - + print('Original scores: $scores'); - + // Increase all scores by 10 scores.updateAll((name, score) => score + 10); - + print('Updated scores: $scores'); } ``` @@ -52,4 +60,4 @@ The above code produces the following output: ```shell Original scores: {Alice: 80, Bob: 90, Charlie: 85} Updated scores: {Alice: 90, Bob: 100, Charlie: 95} -``` \ No newline at end of file +```