'use strict';12Object.defineProperty(exports, "__esModule", {3value: true4});56var _createTester = require('./internal/createTester.js');78var _createTester2 = _interopRequireDefault(_createTester);910var _eachOf = require('./eachOf.js');1112var _eachOf2 = _interopRequireDefault(_eachOf);1314var _awaitify = require('./internal/awaitify.js');1516var _awaitify2 = _interopRequireDefault(_awaitify);1718function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }1920/**21* Returns the first value in `coll` that passes an async truth test. The22* `iteratee` is applied in parallel, meaning the first iteratee to return23* `true` will fire the detect `callback` with that result. That means the24* result might not be the first item in the original `coll` (in terms of order)25* that passes the test.2627* If order within the original `coll` is important, then look at28* [`detectSeries`]{@link module:Collections.detectSeries}.29*30* @name detect31* @static32* @memberOf module:Collections33* @method34* @alias find35* @category Collections36* @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.37* @param {AsyncFunction} iteratee - A truth test to apply to each item in `coll`.38* The iteratee must complete with a boolean value as its result.39* Invoked with (item, callback).40* @param {Function} [callback] - A callback which is called as soon as any41* iteratee returns `true`, or after all the `iteratee` functions have finished.42* Result will be the first item in the array that passes the truth test43* (iteratee) or the value `undefined` if none passed. Invoked with44* (err, result).45* @returns {Promise} a promise, if a callback is omitted46* @example47*48* // dir1 is a directory that contains file1.txt, file2.txt49* // dir2 is a directory that contains file3.txt, file4.txt50* // dir3 is a directory that contains file5.txt51*52* // asynchronous function that checks if a file exists53* function fileExists(file, callback) {54* fs.access(file, fs.constants.F_OK, (err) => {55* callback(null, !err);56* });57* }58*59* async.detect(['file3.txt','file2.txt','dir1/file1.txt'], fileExists,60* function(err, result) {61* console.log(result);62* // dir1/file1.txt63* // result now equals the first file in the list that exists64* }65*);66*67* // Using Promises68* async.detect(['file3.txt','file2.txt','dir1/file1.txt'], fileExists)69* .then(result => {70* console.log(result);71* // dir1/file1.txt72* // result now equals the first file in the list that exists73* }).catch(err => {74* console.log(err);75* });76*77* // Using async/await78* async () => {79* try {80* let result = await async.detect(['file3.txt','file2.txt','dir1/file1.txt'], fileExists);81* console.log(result);82* // dir1/file1.txt83* // result now equals the file in the list that exists84* }85* catch (err) {86* console.log(err);87* }88* }89*90*/91function detect(coll, iteratee, callback) {92return (0, _createTester2.default)(bool => bool, (res, item) => item)(_eachOf2.default, coll, iteratee, callback);93}94exports.default = (0, _awaitify2.default)(detect, 3);95module.exports = exports['default'];9697