Skip to content

Commit

Permalink
Added asyncWrap in multiple places
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-van committed Oct 24, 2021
1 parent 30548fa commit 1752558
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 7 deletions.
4 changes: 4 additions & 0 deletions src/everyLimit.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

import findInternal from './findInternal.mjs'
import Queue from './Queue.mjs'
import asyncWrap from './asyncWrap.mjs'
import assert from 'nanoassert'

/**
* Returns `true` if all elements of an iterable pass a truth test and `false` otherwise.
Expand Down Expand Up @@ -42,6 +44,8 @@ import Queue from './Queue.mjs'
* })
*/
async function everyLimit (iterable, iteratee, concurrencyOrQueue) {
assert(typeof iteratee === 'function', 'iteratee must be a function')
iteratee = asyncWrap(iteratee)
const [index] = await findInternal(iterable, async (value, index, iterable) => {
return !(await iteratee(value, index, iterable))
}, concurrencyOrQueue, false)
Expand Down
2 changes: 2 additions & 0 deletions src/filterLimit.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import mapGenerator from './mapGenerator.mjs'
import assert from 'nanoassert'
import Queue from './Queue.mjs'
import asyncWrap from './asyncWrap.mjs'

/**
* Returns a new array of all the values in iterable which pass an asynchronous truth test.
Expand Down Expand Up @@ -41,6 +42,7 @@ import Queue from './Queue.mjs'
*/
async function filterLimit (iterable, iteratee, concurrencyOrQueue, ordered = true) {
assert(typeof iteratee === 'function', 'iteratee must be a function')
iteratee = asyncWrap(iteratee)
const results = []
for await (const [value, pass] of mapGenerator(iterable, async (v, i, t) => {
return [v, await iteratee(v, i, t)]
Expand Down
2 changes: 0 additions & 2 deletions src/findIndexLimit.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

import findInternal from './findInternal.mjs'
import assert from 'nanoassert'
import Queue from './Queue.mjs'

/**
Expand Down Expand Up @@ -41,7 +40,6 @@ import Queue from './Queue.mjs'
* })
*/
async function findIndexLimit (iterable, iteratee, concurrencyOrQueue) {
assert(typeof iteratee === 'function', 'iteratee must be a function')
const result = (await findInternal(iterable, iteratee, concurrencyOrQueue))[0]
return result
}
Expand Down
2 changes: 0 additions & 2 deletions src/findLimit.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

import findInternal from './findInternal.mjs'
import assert from 'nanoassert'
import Queue from './Queue.mjs'

/**
Expand Down Expand Up @@ -45,7 +44,6 @@ import Queue from './Queue.mjs'
* })
*/
async function findLimit (iterable, iteratee, concurrencyOrQueue) {
assert(typeof iteratee === 'function', 'iteratee must be a function')
const result = (await findInternal(iterable, iteratee, concurrencyOrQueue))[1]
return result
}
Expand Down
2 changes: 0 additions & 2 deletions src/mapLimit.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

import assert from 'nanoassert'
import mapGenerator from './mapGenerator.mjs'
import Queue from './Queue.mjs'

Expand Down Expand Up @@ -37,7 +36,6 @@ import Queue from './Queue.mjs'
* })
*/
async function mapLimit (iterable, iteratee, concurrencyOrQueue) {
assert(typeof iteratee === 'function', 'iteratee must be a function')
const results = []
for await (const el of mapGenerator(iterable, iteratee, concurrencyOrQueue)) {
results.push(el)
Expand Down
4 changes: 3 additions & 1 deletion src/reduce.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

import assert from 'nanoassert'
import asyncWrap from './asyncWrap.mjs'

/**
* Performs a reduce operation as defined in the `Array.reduce()` method but using an asynchronous
Expand Down Expand Up @@ -32,7 +33,8 @@ import assert from 'nanoassert'
* })
*/
async function reduce (iterable, reducer, initial = undefined) {
assert(typeof reducer === 'function', 'reducer must be a function')
assert(typeof reducer === 'function', 'iteratee must be a function')
reducer = asyncWrap(reducer)
if (initial !== undefined) {
let current = initial
let i = 0
Expand Down
4 changes: 4 additions & 0 deletions src/reduceRight.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@

import reduce from './reduce.mjs'
import assert from 'nanoassert'
import asyncWrap from './asyncWrap.mjs'

/**
* Performs a reduce operation as defined in the `Array.reduceRight()` method but using an asynchronous
Expand Down Expand Up @@ -33,6 +35,8 @@ import reduce from './reduce.mjs'
* })
*/
async function reduceRight (iterable, reducer, initial = undefined) {
assert(typeof reducer === 'function', 'iteratee must be a function')
reducer = asyncWrap(reducer)
const arr = []
for await (const el of iterable) {
arr.push(el)
Expand Down

0 comments on commit 1752558

Please sign in to comment.