栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

Flutter Iterable.reduce

Flutter Iterable.reduce

Iterable.reduce 概念

官方解释:

Reduces a collection to a single value by iteratively combining elements
/// of the collection using the provided function.
///
/// The iterable must have at least one element.
/// If it has only one element, that element is returned.
///
/// Otherwise this method starts with the first element from the iterator,
/// and then combines it with the remaining elements in iteration order,
/// as if by:
/// dart /// E value = iterable.first; /// iterable.skip(1).forEach((element) { /// value = combine(value, element); /// }); /// return value; ///
/// Example of calculating the sum of an iterable:
/// ```dart
/// iterable.reduce((value, element) => value + element);

我看了反正是没看懂,实践是检验真理的唯一标准

List testList = ["111","222","333"];
var reduce = testList.reduce((value, element) => value + "=" + element);
print("reduce: $reduce");

输出结果: reduce: 111=222=333

简单来说就是将集合按照指定规则合并为一个字符串,感兴趣的可以自己测试一下

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/745740.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号