every 方法

bool every(
  1. bool test(
    1. E element
    )
)
override

检查此可迭代的每个元素是否都满足 test

按迭代顺序检查每个元素,如果任何元素使 test 返回 false,则返回 false,否则返回 true。如果可迭代为空,则返回 true

示例

final planetsByMass = <double, String>{0.06: 'Mercury', 0.81: 'Venus',
  0.11: 'Mars'};
// Checks whether all keys are smaller than 1.
final every = planetsByMass.keys.every((key) => key < 1.0); // true

实现

bool every(bool test(E element)) {
  int length = this.length;
  for (int i = 0; i < length; i++) {
    if (!test(this[i])) return false;
    if (length != this.length) {
      throw ConcurrentModificationError(this);
    }
  }
  return true;
}