Created
July 25, 2019 10:06
-
-
Save skyjur/c528e71f2e7b702ec1c51e8b3883f54a to your computer and use it in GitHub Desktop.
Folding maps
This file contains 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
void main() { | |
final map = { | |
Product(price: 1): 2, | |
Product(price: 2): 3, | |
}; | |
final total = map.entries.fold( | |
0, | |
(total, entry) => total + (entry.key.price * entry.value) | |
); | |
print('total $total'); | |
} | |
class Product { | |
final price; | |
Product({this.price}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment