find.js.flow 485 B

1234567891011121314151617181920
  1. // @flow strict
  2. declare function find<T>(
  3. list: $ReadOnlyArray<T>,
  4. predicate: (item: T) => boolean,
  5. ): T | void;
  6. /* eslint-disable no-redeclare */
  7. // $FlowFixMe[name-already-bound]
  8. const find = Array.prototype.find
  9. ? function (list, predicate) {
  10. return Array.prototype.find.call(list, predicate);
  11. }
  12. : function (list, predicate) {
  13. for (const value of list) {
  14. if (predicate(value)) {
  15. return value;
  16. }
  17. }
  18. };
  19. export default find;