欢迎您访问365答案网,请分享给你的朋友!
生活常识 学习资料

FlutterIterable.reduce

时间:2023-04-17
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

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

Copyright © 2016-2020 www.365daan.com All Rights Reserved. 365答案网 版权所有 备案号:

部分内容来自互联网,版权归原作者所有,如有冒犯请联系我们,我们将在三个工作时内妥善处理。