-
Notifications
You must be signed in to change notification settings - Fork 0
Async Filter
zak-zaffar edited this page Dec 23, 2019
·
18 revisions
/**
* Async Filter
* Filter an iterable object asynchronously and resolve when all callbacks are resolved
* @async
* @param {Function} callback - callback(currentValue, index, array)
* @param {Object} [thisArg] - must be iterable
* @return {Array}
* @throws {TypeError}
*/
async function asyncFilter(callback, [thisArg]) {...}
const { asyncFilter } = require('iterable-async'),
array = [1, 2, 3, 4, 5];
const found = await asyncFilter(async element => {
return element > 2;
}, array);
console.log('Resolved Array ' , ...found);
// Resolved Array 3, 4, 5
const { asyncFind } = require('iterable-async'),
array = [1, 2, 3, 4, 5];
array.asyncFilter = asyncFilter;
const found = await array.asyncFilter(async element => {
return element > 2;
});
console.log('Resolved Array ' + found);
// Resolved Array 3.4.5