哼!问题是
some
方法是
Iterable
class
而不是在
List
这个
列表
类实现
可迭代的
,尽管如此,我本可以更早地找到它,但我想我在所有这些方法描述中迷失了方向。
Dart等效于
一些
方法被调用:
any
:
Iterable<E>
bool any(bool test(E element))
检查此iterable的任何元素是否满足
test
。
按迭代顺序检查每个元素,如果其中任何元素使测试返回true,则返回true,否则返回false。
示例用法:
// The list in which we want to check if there is an item that passes a certain test.
List<String> haystack = [
// It contains some elements...
];
// Just to be explicit in this example, you don't really need it
typedef TestFunc = bool Function(String);
// The test. Just some function that takes an element and returns boolean.
TestFunc isNeedle = (String v) => v.toLowerCase().contains('needle');
bool gotNeedle = haystack.any(isNeedle);