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;
}