every方法

bool every(
  1. bool test(
    1. E element
    )
)
继承

检查此可迭代中是否每个元素都满足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(elementAt(i))) return false;
    if (length != this.length) {
      throw ConcurrentModificationError(this);
    }
  }
  return true;
}