everySet.js.flow 818 B

123456789101112131415161718192021222324252627282930313233
  1. /**
  2. * Copyright (c) 2013-present, Facebook, Inc.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. *
  7. * @providesModule everySet
  8. * @flow
  9. * @typechecks
  10. */
  11. 'use strict';
  12. import type Set from './Set';
  13. /**
  14. * The everySet() method tests whether all elements in the given Set pass the
  15. * test implemented by the provided function.
  16. */
  17. function everySet<T>(set: Set<T>, callback: (value: T, key: T, set: Set<T>) => boolean, context?: any): boolean {
  18. var iterator = set.entries();
  19. var current = iterator.next();
  20. while (!current.done) {
  21. var entry = current.value;
  22. if (!callback.call(context, entry[1], entry[0], set)) {
  23. return false;
  24. }
  25. current = iterator.next();
  26. }
  27. return true;
  28. }
  29. module.exports = everySet;