-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
asyncGroupBy
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
|
||
import Queue from './Queue.mjs' | ||
Check failure on line 2 in src/asyncFilterObject.mjs GitHub Actions / test (20.x)
Check failure on line 2 in src/asyncFilterObject.mjs GitHub Actions / test (18.x)
Check failure on line 2 in src/asyncFilterObject.mjs GitHub Actions / test (22.x)
Check failure on line 2 in src/asyncFilterObject.mjs GitHub Actions / test (12.x)
Check failure on line 2 in src/asyncFilterObject.mjs GitHub Actions / test (14.x)
Check failure on line 2 in src/asyncFilterObject.mjs GitHub Actions / test (16.x)
|
||
import asyncFromEntries from './asyncFromEntries.mjs' | ||
import asyncGeneratorFilter from './asyncGeneratorFilter.mjs' | ||
import generatorEntries from './generatorEntries.mjs' | ||
import asyncWrap from './asyncWrap.mjs' | ||
|
||
async function asyncFilterObject (obj, iteratee, queueOrConcurrency = 1) { | ||
Check failure on line 8 in src/asyncFilterObject.mjs GitHub Actions / test (20.x)
Check warning on line 8 in src/asyncFilterObject.mjs GitHub Actions / test (20.x)
Check failure on line 8 in src/asyncFilterObject.mjs GitHub Actions / test (18.x)
Check warning on line 8 in src/asyncFilterObject.mjs GitHub Actions / test (18.x)
Check failure on line 8 in src/asyncFilterObject.mjs GitHub Actions / test (22.x)
Check warning on line 8 in src/asyncFilterObject.mjs GitHub Actions / test (22.x)
Check failure on line 8 in src/asyncFilterObject.mjs GitHub Actions / test (12.x)
Check warning on line 8 in src/asyncFilterObject.mjs GitHub Actions / test (12.x)
Check failure on line 8 in src/asyncFilterObject.mjs GitHub Actions / test (14.x)
Check warning on line 8 in src/asyncFilterObject.mjs GitHub Actions / test (14.x)
Check failure on line 8 in src/asyncFilterObject.mjs GitHub Actions / test (16.x)
Check warning on line 8 in src/asyncFilterObject.mjs GitHub Actions / test (16.x)
Check failure on line 8 in src/asyncFilterObject.mjs GitHub Actions / test (21.x)
|
||
iteratee = asyncWrap(iteratee) | ||
return await asyncFromEntries(asyncGeneratorFilter(generatorEntries(obj), async ([k, v]) => { | ||
return await iteratee(v, k, obj) | ||
}, queueOrConcurrency)) | ||
} | ||
|
||
export default asyncFilterObject |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
|
||
import asyncFindInternal from './asyncFindInternal.mjs' | ||
import generatorEntries from './generatorEntries.mjs' | ||
import Queue from './Queue.mjs' | ||
Check failure on line 4 in src/asyncFindKey.mjs GitHub Actions / test (20.x)
Check failure on line 4 in src/asyncFindKey.mjs GitHub Actions / test (18.x)
Check failure on line 4 in src/asyncFindKey.mjs GitHub Actions / test (22.x)
Check failure on line 4 in src/asyncFindKey.mjs GitHub Actions / test (12.x)
Check failure on line 4 in src/asyncFindKey.mjs GitHub Actions / test (14.x)
Check failure on line 4 in src/asyncFindKey.mjs GitHub Actions / test (16.x)
|
||
|
||
async function asyncFindKey (obj, iteratee, queueOrConcurrency = 1, ordered = false) { | ||
Check failure on line 6 in src/asyncFindKey.mjs GitHub Actions / test (20.x)
Check warning on line 6 in src/asyncFindKey.mjs GitHub Actions / test (20.x)
Check failure on line 6 in src/asyncFindKey.mjs GitHub Actions / test (18.x)
Check warning on line 6 in src/asyncFindKey.mjs GitHub Actions / test (18.x)
Check failure on line 6 in src/asyncFindKey.mjs GitHub Actions / test (22.x)
Check warning on line 6 in src/asyncFindKey.mjs GitHub Actions / test (22.x)
Check failure on line 6 in src/asyncFindKey.mjs GitHub Actions / test (12.x)
Check warning on line 6 in src/asyncFindKey.mjs GitHub Actions / test (12.x)
Check failure on line 6 in src/asyncFindKey.mjs GitHub Actions / test (14.x)
Check warning on line 6 in src/asyncFindKey.mjs GitHub Actions / test (14.x)
Check failure on line 6 in src/asyncFindKey.mjs GitHub Actions / test (16.x)
Check warning on line 6 in src/asyncFindKey.mjs GitHub Actions / test (16.x)
Check failure on line 6 in src/asyncFindKey.mjs GitHub Actions / test (21.x)
|
||
iteratee = asyncWrap(iteratee) | ||
Check failure on line 7 in src/asyncFindKey.mjs GitHub Actions / test (20.x)
Check failure on line 7 in src/asyncFindKey.mjs GitHub Actions / test (18.x)
Check failure on line 7 in src/asyncFindKey.mjs GitHub Actions / test (22.x)
Check failure on line 7 in src/asyncFindKey.mjs GitHub Actions / test (12.x)
Check failure on line 7 in src/asyncFindKey.mjs GitHub Actions / test (14.x)
Check failure on line 7 in src/asyncFindKey.mjs GitHub Actions / test (16.x)
|
||
const [k, _] = (await asyncFindInternal(generatorEntries(obj), async ([k, v]) => { | ||
Check failure on line 8 in src/asyncFindKey.mjs GitHub Actions / test (20.x)
Check failure on line 8 in src/asyncFindKey.mjs GitHub Actions / test (18.x)
Check failure on line 8 in src/asyncFindKey.mjs GitHub Actions / test (22.x)
Check failure on line 8 in src/asyncFindKey.mjs GitHub Actions / test (12.x)
Check failure on line 8 in src/asyncFindKey.mjs GitHub Actions / test (14.x)
Check failure on line 8 in src/asyncFindKey.mjs GitHub Actions / test (16.x)
|
||
return await iteratee(v, k, obj) | ||
}, queueOrConcurrency, ordered))[1] | ||
return k | ||
} | ||
|
||
export default asyncFindKey |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
|
||
import asyncGeneratorMap from './asyncGeneratorMap.mjs' | ||
import generatorEntries from './generatorEntries.mjs' | ||
import Queue from './Queue.mjs' | ||
Check failure on line 4 in src/asyncForEachObject.mjs GitHub Actions / test (20.x)
Check failure on line 4 in src/asyncForEachObject.mjs GitHub Actions / test (18.x)
Check failure on line 4 in src/asyncForEachObject.mjs GitHub Actions / test (22.x)
Check failure on line 4 in src/asyncForEachObject.mjs GitHub Actions / test (12.x)
Check failure on line 4 in src/asyncForEachObject.mjs GitHub Actions / test (14.x)
Check failure on line 4 in src/asyncForEachObject.mjs GitHub Actions / test (16.x)
|
||
|
||
async function asyncForEachObject (obj, iteratee, queueOrConcurrency = 1) { | ||
Check failure on line 6 in src/asyncForEachObject.mjs GitHub Actions / test (20.x)
Check warning on line 6 in src/asyncForEachObject.mjs GitHub Actions / test (20.x)
Check failure on line 6 in src/asyncForEachObject.mjs GitHub Actions / test (18.x)
Check warning on line 6 in src/asyncForEachObject.mjs GitHub Actions / test (18.x)
Check failure on line 6 in src/asyncForEachObject.mjs GitHub Actions / test (22.x)
Check warning on line 6 in src/asyncForEachObject.mjs GitHub Actions / test (22.x)
Check failure on line 6 in src/asyncForEachObject.mjs GitHub Actions / test (12.x)
Check warning on line 6 in src/asyncForEachObject.mjs GitHub Actions / test (12.x)
Check failure on line 6 in src/asyncForEachObject.mjs GitHub Actions / test (14.x)
Check warning on line 6 in src/asyncForEachObject.mjs GitHub Actions / test (14.x)
Check failure on line 6 in src/asyncForEachObject.mjs GitHub Actions / test (16.x)
Check warning on line 6 in src/asyncForEachObject.mjs GitHub Actions / test (16.x)
Check failure on line 6 in src/asyncForEachObject.mjs GitHub Actions / test (21.x)
|
||
iteratee = asyncWrap(iteratee) | ||
Check failure on line 7 in src/asyncForEachObject.mjs GitHub Actions / test (20.x)
Check failure on line 7 in src/asyncForEachObject.mjs GitHub Actions / test (18.x)
Check failure on line 7 in src/asyncForEachObject.mjs GitHub Actions / test (22.x)
Check failure on line 7 in src/asyncForEachObject.mjs GitHub Actions / test (12.x)
Check failure on line 7 in src/asyncForEachObject.mjs GitHub Actions / test (14.x)
Check failure on line 7 in src/asyncForEachObject.mjs GitHub Actions / test (16.x)
|
||
// eslint-disable-next-line no-unused-vars | ||
for await (const _el of asyncGeneratorMap(generatorEntries(obj), async ([k, v]) => { | ||
await iteratee(v, k, obj) | ||
}, queueOrConcurrency, false)) { | ||
// do nothing | ||
} | ||
} | ||
|
||
export default asyncForEachObject |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
|
||
import asyncGeneratorMap from './asyncGeneratorMap.mjs' | ||
import asyncWrap from './asyncWrap.mjs' | ||
import Queue from './Queue.mjs' | ||
Check failure on line 4 in src/asyncGroupBy.mjs GitHub Actions / test (20.x)
Check failure on line 4 in src/asyncGroupBy.mjs GitHub Actions / test (18.x)
Check failure on line 4 in src/asyncGroupBy.mjs GitHub Actions / test (22.x)
Check failure on line 4 in src/asyncGroupBy.mjs GitHub Actions / test (12.x)
Check failure on line 4 in src/asyncGroupBy.mjs GitHub Actions / test (14.x)
Check failure on line 4 in src/asyncGroupBy.mjs GitHub Actions / test (16.x)
|
||
|
||
async function asyncGroupBy (iterable, iteratee, queueOrConcurrency = 1) { | ||
Check warning on line 6 in src/asyncGroupBy.mjs GitHub Actions / test (20.x)
Check warning on line 6 in src/asyncGroupBy.mjs GitHub Actions / test (18.x)
Check warning on line 6 in src/asyncGroupBy.mjs GitHub Actions / test (22.x)
Check warning on line 6 in src/asyncGroupBy.mjs GitHub Actions / test (12.x)
Check warning on line 6 in src/asyncGroupBy.mjs GitHub Actions / test (14.x)
Check warning on line 6 in src/asyncGroupBy.mjs GitHub Actions / test (16.x)
|
||
interatee = asyncWrap(iteratee) | ||
const groups = {} | ||
for await (const [group, value] of asyncGeneratorMap(iterable, async (v, i, it) => | ||
{ | ||
const group = await iteratee(v, i, it) | ||
return [group, v] | ||
}, queueOrConcurrency)) | ||
{ | ||
if (!(group in groups)) | ||
{ | ||
groups[group] = [] | ||
} | ||
groups[group].push(value) | ||
} | ||
return groups | ||
} |