find.js.flow 464 B

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