Last active
March 8, 2019 08:56
-
-
Save fariswd/b01c9f787b84506dfad90a842aa3440a to your computer and use it in GitHub Desktop.
immutable groceries
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// js | |
const groceries = { | |
fruit: ['apple', 'orange', 'grapes'], | |
}; | |
const newGroceries = { | |
...groceries, | |
fruit: [ | |
...groceries.fruit, | |
'lychee' | |
] | |
} | |
console.log(groceries) | |
console.log(newGroceries) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//dart | |
void main() { | |
Map groceries = { | |
'fruit': ['apple', 'orange', 'grapes'], | |
}; | |
Map newGroceries = Map() | |
..addAll(groceries) | |
..update( | |
'fruit', | |
(_) => [] | |
..addAll(groceries['fruit']) | |
..add('lychee')); | |
print(groceries); | |
print(newGroceries); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment