From e0eb50353d16592e15c6f03898bcf4b2e0a60afe Mon Sep 17 00:00:00 2001 From: omkar hole Date: Sat, 20 Dec 2025 20:36:12 +0530 Subject: [PATCH 1/3] Add Dart Map .map() term documentation This pull request adds a new term entry for the Dart Map.map() method. The entry explains how .map() transforms each key-value pair of a map into a new map using a provided function. It includes a clear syntax section and a simple example demonstrating the method in use, following Codecademy Docs content standards and writing guidelines. This addition helps learners better understand how to work with Dart maps in a clear and beginner-friendly way. --- content/dart/concepts/map/terms/map/map.md | 87 ++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 content/dart/concepts/map/terms/map/map.md diff --git a/content/dart/concepts/map/terms/map/map.md b/content/dart/concepts/map/terms/map/map.md new file mode 100644 index 00000000000..1662872457a --- /dev/null +++ b/content/dart/concepts/map/terms/map/map.md @@ -0,0 +1,87 @@ +--- +Title: 'Map.map()' +Description: 'Map.map() transforms each key-value pair in a Dart Map into a new Map.' +Subjects: + - 'Computer Science' + - 'Web Development' +Tags: + - 'Dart' + - 'Data Structures' + - 'Methods' +CatalogContent: + - 'learn-dart' + - 'paths/computer-science' +--- + +In Dart, the `.map()` method is used to create a new map by transforming each key-value pair of an existing map using a provided function. + +## Syntax + +```pseudo +myMap.map((key, value) => MapEntry(newKey, newValue)) +``` + +- `myMap`: The map whose entries are to be transformed. +- `key`: The key from the original map. +- `value`: The value associated with the key. +- `MapEntry`: Represents a single key-value pair in the new map. + +## Example 1 + +In the following example, the `.map()` method is used to create a new map by increasing each value by 1: + +```dart +void main() { + Map myMap = { + 'a': 1, + 'b': 2, + 'c': 3 + }; + + print('Original Map: $myMap'); + + // Using .map() to increase each value by 1 + Map newMap = myMap.map( + (key, value) => MapEntry(key, value + 1) + ); + + print('New Map after using .map(): $newMap'); +} +``` + +Here is the output for the above example: + +```shell +Original Map: {a: 1, b: 2, c: 3} +New Map after using .map(): {a: 2, b: 3, c: 4} +``` + +## Example 2 + +In the following example, the `.map()` method is used to convert all values in a map to uppercase: + +```dart +void main() { + Map myMap = { + 'x': 'apple', + 'y': 'banana', + 'z': 'cherry' + }; + + print('Original Map: $myMap'); + + // Using .map() to convert values to uppercase + Map newMap = myMap.map( + (key, value) => MapEntry(key, value.toUpperCase()) + ); + + print('New Map after using .map(): $newMap'); +} +``` + +Here is the output for the above example: + +```shell +Original Map: {x: apple, y: banana, z: cherry} +New Map after using .map(): {x: APPLE, y: BANANA, z: CHERRY} +``` \ No newline at end of file From e2578ec9e1bbfd49cd2b5f156a11be26385e9d34 Mon Sep 17 00:00:00 2001 From: Omkar Hole <182200831+omkarhole@users.noreply.github.com> Date: Sat, 20 Dec 2025 20:42:31 +0530 Subject: [PATCH 2/3] Update title and description for map.md --- content/dart/concepts/map/terms/map/map.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/content/dart/concepts/map/terms/map/map.md b/content/dart/concepts/map/terms/map/map.md index 1662872457a..d8847389086 100644 --- a/content/dart/concepts/map/terms/map/map.md +++ b/content/dart/concepts/map/terms/map/map.md @@ -1,13 +1,13 @@ --- -Title: 'Map.map()' -Description: 'Map.map() transforms each key-value pair in a Dart Map into a new Map.' +Title: '.map()' +Description: '.map() transforms each key-value pair in a Dart Map into a new Map.' Subjects: - 'Computer Science' - 'Web Development' Tags: - 'Dart' - 'Data Structures' - - 'Methods' + - 'Map' CatalogContent: - 'learn-dart' - 'paths/computer-science' @@ -84,4 +84,4 @@ Here is the output for the above example: ```shell Original Map: {x: apple, y: banana, z: cherry} New Map after using .map(): {x: APPLE, y: BANANA, z: CHERRY} -``` \ No newline at end of file +``` From c6cc545263f97be54db0c59c2c1d3a38685aeacc Mon Sep 17 00:00:00 2001 From: Mamta Wardhani Date: Mon, 22 Dec 2025 15:48:28 +0530 Subject: [PATCH 3/3] Revise .map() method documentation Updated the description and improved clarity of the .map() method documentation. --- content/dart/concepts/map/terms/map/map.md | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/content/dart/concepts/map/terms/map/map.md b/content/dart/concepts/map/terms/map/map.md index d8847389086..c7c1c746293 100644 --- a/content/dart/concepts/map/terms/map/map.md +++ b/content/dart/concepts/map/terms/map/map.md @@ -1,6 +1,6 @@ --- Title: '.map()' -Description: '.map() transforms each key-value pair in a Dart Map into a new Map.' +Description: 'Creates a new map by transforming each key–value pair of an existing map using a provided function.' Subjects: - 'Computer Science' - 'Web Development' @@ -13,7 +13,7 @@ CatalogContent: - 'paths/computer-science' --- -In Dart, the `.map()` method is used to create a new map by transforming each key-value pair of an existing map using a provided function. +In Dart, the **`.map()`** method creates a new map by transforming each key–value pair of an existing map using a provided function. ## Syntax @@ -21,10 +21,20 @@ In Dart, the `.map()` method is used to create a new map by transforming each ke myMap.map((key, value) => MapEntry(newKey, newValue)) ``` -- `myMap`: The map whose entries are to be transformed. -- `key`: The key from the original map. -- `value`: The value associated with the key. -- `MapEntry`: Represents a single key-value pair in the new map. +Here, `myMap` is the map whose entries are to be transformed. + +**Parameters:** + +- A function that takes two arguments: + - `key`: The key from the original map. + - `value`: The value associated with that key. +- The function must return a `MapEntry`, which defines the key–value pair in the new map. + +**Return value:** + +The `.map()` method returns a new `Map` containing the transformed key–value pairs. + +> **Note:** The original map remains unchanged. ## Example 1