Skip to content

Instantly share code, notes, and snippets.

@skyjur
Created July 25, 2019 10:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skyjur/c528e71f2e7b702ec1c51e8b3883f54a to your computer and use it in GitHub Desktop.
Save skyjur/c528e71f2e7b702ec1c51e8b3883f54a to your computer and use it in GitHub Desktop.
Folding maps
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