We will learn how to work with Lists using a variety of methods made available in the dart:core library. We will explore the top methods for working with List type collections.

Learn more about Lists at https://api.dartlang.org/stable/2.2.0/dart-core/List-class.html

Array to list:

because .map return iterable.

  var fruits = ['banana', 'pineapple', 'orange', 'watermelon', 'apple'];
var fiboNumbers = [, , , , , , ];
List<Map<String, dynamic>> users = [
{ 'name': 'John', 'age': },
{ 'name': 'Jane', 'age': },
{ 'name': 'Mary', 'age': },
]; // array to list
var mappedFruits = fruits.map((fruit) => 'I love $fruit').toList();
print(mappedFruits);

reduce vs fold:

reduce: doesn't provide the init value, but 'fold' does:

  const initialValue = ;
var sum2 = fiboNumbers.fold(initialValue, (curr, next) => curr + next);
print( sum2 ); var sum = fiboNumbers.reduce((curr, next) => curr + next);
print( sum );

filtering:

  var over21s = users.where((user) => user['age'] > );
print( over21s.length ); var nameJ = users.firstWhere((user) => user['name'].startsWith('J'), orElse: () => null);
print( nameJ ); var under18 = users.singleWhere((user) => user['age'] < , orElse: () => {'error': 'Not Found'});
print( under18 );

take & skip:

  print( fiboNumbers.take().toList() );
print( fiboNumbers.skip().toList() );
print( fiboNumbers.take().skip().take().toList() );

expend: the same as flatMap in JS

  var flattened = [[, ], [, ]].expand((pair) => pair).toList();
print( flattened ); var duplicated = fiboNumbers.expand((i) => [i, i]).toList();
print( duplicated );

最新文章

  1. iOS监听tableView组头切换事件
  2. vue中v-bind:class动态添加class
  3. C#正则表达式Regex常用匹配
  4. C# 通过代理获取url数据
  5. 《CSS3实战》读书笔记 第三章:选择器:样式实现的标记
  6. Ruiy自我识人做事领悟录ing
  7. EAI概述
  8. oracle服务介绍
  9. PAT---1005. Spell It Right (20)
  10. JS学习之prototype属性
  11. 如何利用【百度地图API】进行定位?非GPS定位
  12. 【JAVA笔记】JAVA后端实现统一扫码支付:微信篇
  13. 小练习,判断X的奇偶性
  14. (2018干货系列三)最新PHP学习路线整合
  15. KVM环境安装macOS Sierra
  16. python之属性描述符与属性查找规则
  17. 在window下安装第二个mysql
  18. 很简单的在Ubuntu系统下安装字体和切换默认字体的方法
  19. laravel5的Bcrypt加密方式对系统保存密码的小结
  20. QT的信号和槽机制简介

热门文章

  1. SQL语言(二)
  2. django使用pyecharts(5)----django加入echarts_增量更新_定长
  3. WUSTOJ 1337: Car race game(C)树状数组,离散化
  4. matplotlib实例笔记
  5. go select 的default
  6. 使用 react 的 hooks 进行全局的状态管理
  7. 解决阿里云OSS The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint的办法
  8. 使用Harbor搭建Docker私有镜像仓库
  9. 从零开始搭建一个简单的基于webpack的vue开发环境
  10. 数据结构之队列(queue)