Skip to content

Commit

Permalink
Adds asyncFilterObject, asyncFindKey, asyncForEachObject and
Browse files Browse the repository at this point in the history
asyncGroupBy
  • Loading branch information
nicolas-van committed Aug 20, 2024
1 parent bd625e8 commit a931683
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/asyncFilterObject.mjs
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

View workflow job for this annotation

GitHub Actions / test (20.x)

'Queue' is defined but never used

Check failure on line 2 in src/asyncFilterObject.mjs

View workflow job for this annotation

GitHub Actions / test (18.x)

'Queue' is defined but never used

Check failure on line 2 in src/asyncFilterObject.mjs

View workflow job for this annotation

GitHub Actions / test (22.x)

'Queue' is defined but never used

Check failure on line 2 in src/asyncFilterObject.mjs

View workflow job for this annotation

GitHub Actions / test (12.x)

'Queue' is defined but never used

Check failure on line 2 in src/asyncFilterObject.mjs

View workflow job for this annotation

GitHub Actions / test (14.x)

'Queue' is defined but never used

Check failure on line 2 in src/asyncFilterObject.mjs

View workflow job for this annotation

GitHub Actions / test (16.x)

'Queue' is defined but never used

Check failure on line 2 in src/asyncFilterObject.mjs

View workflow job for this annotation

GitHub Actions / test (21.x)

'Queue' is defined but never used
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

View workflow job for this annotation

GitHub Actions / test (20.x)

Missing JSDoc comment

Check warning on line 8 in src/asyncFilterObject.mjs

View workflow job for this annotation

GitHub Actions / test (20.x)

Missing JSDoc comment

Check failure on line 8 in src/asyncFilterObject.mjs

View workflow job for this annotation

GitHub Actions / test (18.x)

Missing JSDoc comment

Check warning on line 8 in src/asyncFilterObject.mjs

View workflow job for this annotation

GitHub Actions / test (18.x)

Missing JSDoc comment

Check failure on line 8 in src/asyncFilterObject.mjs

View workflow job for this annotation

GitHub Actions / test (22.x)

Missing JSDoc comment

Check warning on line 8 in src/asyncFilterObject.mjs

View workflow job for this annotation

GitHub Actions / test (22.x)

Missing JSDoc comment

Check failure on line 8 in src/asyncFilterObject.mjs

View workflow job for this annotation

GitHub Actions / test (12.x)

Missing JSDoc comment

Check warning on line 8 in src/asyncFilterObject.mjs

View workflow job for this annotation

GitHub Actions / test (12.x)

Missing JSDoc comment

Check failure on line 8 in src/asyncFilterObject.mjs

View workflow job for this annotation

GitHub Actions / test (14.x)

Missing JSDoc comment

Check warning on line 8 in src/asyncFilterObject.mjs

View workflow job for this annotation

GitHub Actions / test (14.x)

Missing JSDoc comment

Check failure on line 8 in src/asyncFilterObject.mjs

View workflow job for this annotation

GitHub Actions / test (16.x)

Missing JSDoc comment

Check warning on line 8 in src/asyncFilterObject.mjs

View workflow job for this annotation

GitHub Actions / test (16.x)

Missing JSDoc comment

Check failure on line 8 in src/asyncFilterObject.mjs

View workflow job for this annotation

GitHub Actions / test (21.x)

Missing JSDoc comment

Check warning on line 8 in src/asyncFilterObject.mjs

View workflow job for this annotation

GitHub Actions / test (21.x)

Missing JSDoc comment
iteratee = asyncWrap(iteratee)
return await asyncFromEntries(asyncGeneratorFilter(generatorEntries(obj), async ([k, v]) => {
return await iteratee(v, k, obj)
}, queueOrConcurrency))
}

export default asyncFilterObject
14 changes: 14 additions & 0 deletions src/asyncFindKey.mjs
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

View workflow job for this annotation

GitHub Actions / test (20.x)

'Queue' is defined but never used

Check failure on line 4 in src/asyncFindKey.mjs

View workflow job for this annotation

GitHub Actions / test (18.x)

'Queue' is defined but never used

Check failure on line 4 in src/asyncFindKey.mjs

View workflow job for this annotation

GitHub Actions / test (22.x)

'Queue' is defined but never used

Check failure on line 4 in src/asyncFindKey.mjs

View workflow job for this annotation

GitHub Actions / test (12.x)

'Queue' is defined but never used

Check failure on line 4 in src/asyncFindKey.mjs

View workflow job for this annotation

GitHub Actions / test (14.x)

'Queue' is defined but never used

Check failure on line 4 in src/asyncFindKey.mjs

View workflow job for this annotation

GitHub Actions / test (16.x)

'Queue' is defined but never used

Check failure on line 4 in src/asyncFindKey.mjs

View workflow job for this annotation

GitHub Actions / test (21.x)

'Queue' is defined but never used

async function asyncFindKey (obj, iteratee, queueOrConcurrency = 1, ordered = false) {

Check failure on line 6 in src/asyncFindKey.mjs

View workflow job for this annotation

GitHub Actions / test (20.x)

Missing JSDoc comment

Check warning on line 6 in src/asyncFindKey.mjs

View workflow job for this annotation

GitHub Actions / test (20.x)

Missing JSDoc comment

Check failure on line 6 in src/asyncFindKey.mjs

View workflow job for this annotation

GitHub Actions / test (18.x)

Missing JSDoc comment

Check warning on line 6 in src/asyncFindKey.mjs

View workflow job for this annotation

GitHub Actions / test (18.x)

Missing JSDoc comment

Check failure on line 6 in src/asyncFindKey.mjs

View workflow job for this annotation

GitHub Actions / test (22.x)

Missing JSDoc comment

Check warning on line 6 in src/asyncFindKey.mjs

View workflow job for this annotation

GitHub Actions / test (22.x)

Missing JSDoc comment

Check failure on line 6 in src/asyncFindKey.mjs

View workflow job for this annotation

GitHub Actions / test (12.x)

Missing JSDoc comment

Check warning on line 6 in src/asyncFindKey.mjs

View workflow job for this annotation

GitHub Actions / test (12.x)

Missing JSDoc comment

Check failure on line 6 in src/asyncFindKey.mjs

View workflow job for this annotation

GitHub Actions / test (14.x)

Missing JSDoc comment

Check warning on line 6 in src/asyncFindKey.mjs

View workflow job for this annotation

GitHub Actions / test (14.x)

Missing JSDoc comment

Check failure on line 6 in src/asyncFindKey.mjs

View workflow job for this annotation

GitHub Actions / test (16.x)

Missing JSDoc comment

Check warning on line 6 in src/asyncFindKey.mjs

View workflow job for this annotation

GitHub Actions / test (16.x)

Missing JSDoc comment

Check failure on line 6 in src/asyncFindKey.mjs

View workflow job for this annotation

GitHub Actions / test (21.x)

Missing JSDoc comment

Check warning on line 6 in src/asyncFindKey.mjs

View workflow job for this annotation

GitHub Actions / test (21.x)

Missing JSDoc comment
iteratee = asyncWrap(iteratee)

Check failure on line 7 in src/asyncFindKey.mjs

View workflow job for this annotation

GitHub Actions / test (20.x)

'asyncWrap' is not defined

Check failure on line 7 in src/asyncFindKey.mjs

View workflow job for this annotation

GitHub Actions / test (18.x)

'asyncWrap' is not defined

Check failure on line 7 in src/asyncFindKey.mjs

View workflow job for this annotation

GitHub Actions / test (22.x)

'asyncWrap' is not defined

Check failure on line 7 in src/asyncFindKey.mjs

View workflow job for this annotation

GitHub Actions / test (12.x)

'asyncWrap' is not defined

Check failure on line 7 in src/asyncFindKey.mjs

View workflow job for this annotation

GitHub Actions / test (14.x)

'asyncWrap' is not defined

Check failure on line 7 in src/asyncFindKey.mjs

View workflow job for this annotation

GitHub Actions / test (16.x)

'asyncWrap' is not defined

Check failure on line 7 in src/asyncFindKey.mjs

View workflow job for this annotation

GitHub Actions / test (21.x)

'asyncWrap' is not defined
const [k, _] = (await asyncFindInternal(generatorEntries(obj), async ([k, v]) => {

Check failure on line 8 in src/asyncFindKey.mjs

View workflow job for this annotation

GitHub Actions / test (20.x)

'_' is assigned a value but never used

Check failure on line 8 in src/asyncFindKey.mjs

View workflow job for this annotation

GitHub Actions / test (18.x)

'_' is assigned a value but never used

Check failure on line 8 in src/asyncFindKey.mjs

View workflow job for this annotation

GitHub Actions / test (22.x)

'_' is assigned a value but never used

Check failure on line 8 in src/asyncFindKey.mjs

View workflow job for this annotation

GitHub Actions / test (12.x)

'_' is assigned a value but never used

Check failure on line 8 in src/asyncFindKey.mjs

View workflow job for this annotation

GitHub Actions / test (14.x)

'_' is assigned a value but never used

Check failure on line 8 in src/asyncFindKey.mjs

View workflow job for this annotation

GitHub Actions / test (16.x)

'_' is assigned a value but never used

Check failure on line 8 in src/asyncFindKey.mjs

View workflow job for this annotation

GitHub Actions / test (21.x)

'_' is assigned a value but never used
return await iteratee(v, k, obj)
}, queueOrConcurrency, ordered))[1]
return k
}

export default asyncFindKey
16 changes: 16 additions & 0 deletions src/asyncForEachObject.mjs
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

View workflow job for this annotation

GitHub Actions / test (20.x)

'Queue' is defined but never used

Check failure on line 4 in src/asyncForEachObject.mjs

View workflow job for this annotation

GitHub Actions / test (18.x)

'Queue' is defined but never used

Check failure on line 4 in src/asyncForEachObject.mjs

View workflow job for this annotation

GitHub Actions / test (22.x)

'Queue' is defined but never used

Check failure on line 4 in src/asyncForEachObject.mjs

View workflow job for this annotation

GitHub Actions / test (12.x)

'Queue' is defined but never used

Check failure on line 4 in src/asyncForEachObject.mjs

View workflow job for this annotation

GitHub Actions / test (14.x)

'Queue' is defined but never used

Check failure on line 4 in src/asyncForEachObject.mjs

View workflow job for this annotation

GitHub Actions / test (16.x)

'Queue' is defined but never used

Check failure on line 4 in src/asyncForEachObject.mjs

View workflow job for this annotation

GitHub Actions / test (21.x)

'Queue' is defined but never used

async function asyncForEachObject (obj, iteratee, queueOrConcurrency = 1) {

Check failure on line 6 in src/asyncForEachObject.mjs

View workflow job for this annotation

GitHub Actions / test (20.x)

Missing JSDoc comment

Check warning on line 6 in src/asyncForEachObject.mjs

View workflow job for this annotation

GitHub Actions / test (20.x)

Missing JSDoc comment

Check failure on line 6 in src/asyncForEachObject.mjs

View workflow job for this annotation

GitHub Actions / test (18.x)

Missing JSDoc comment

Check warning on line 6 in src/asyncForEachObject.mjs

View workflow job for this annotation

GitHub Actions / test (18.x)

Missing JSDoc comment

Check failure on line 6 in src/asyncForEachObject.mjs

View workflow job for this annotation

GitHub Actions / test (22.x)

Missing JSDoc comment

Check warning on line 6 in src/asyncForEachObject.mjs

View workflow job for this annotation

GitHub Actions / test (22.x)

Missing JSDoc comment

Check failure on line 6 in src/asyncForEachObject.mjs

View workflow job for this annotation

GitHub Actions / test (12.x)

Missing JSDoc comment

Check warning on line 6 in src/asyncForEachObject.mjs

View workflow job for this annotation

GitHub Actions / test (12.x)

Missing JSDoc comment

Check failure on line 6 in src/asyncForEachObject.mjs

View workflow job for this annotation

GitHub Actions / test (14.x)

Missing JSDoc comment

Check warning on line 6 in src/asyncForEachObject.mjs

View workflow job for this annotation

GitHub Actions / test (14.x)

Missing JSDoc comment

Check failure on line 6 in src/asyncForEachObject.mjs

View workflow job for this annotation

GitHub Actions / test (16.x)

Missing JSDoc comment

Check warning on line 6 in src/asyncForEachObject.mjs

View workflow job for this annotation

GitHub Actions / test (16.x)

Missing JSDoc comment

Check failure on line 6 in src/asyncForEachObject.mjs

View workflow job for this annotation

GitHub Actions / test (21.x)

Missing JSDoc comment

Check warning on line 6 in src/asyncForEachObject.mjs

View workflow job for this annotation

GitHub Actions / test (21.x)

Missing JSDoc comment
iteratee = asyncWrap(iteratee)

Check failure on line 7 in src/asyncForEachObject.mjs

View workflow job for this annotation

GitHub Actions / test (20.x)

'asyncWrap' is not defined

Check failure on line 7 in src/asyncForEachObject.mjs

View workflow job for this annotation

GitHub Actions / test (18.x)

'asyncWrap' is not defined

Check failure on line 7 in src/asyncForEachObject.mjs

View workflow job for this annotation

GitHub Actions / test (22.x)

'asyncWrap' is not defined

Check failure on line 7 in src/asyncForEachObject.mjs

View workflow job for this annotation

GitHub Actions / test (12.x)

'asyncWrap' is not defined

Check failure on line 7 in src/asyncForEachObject.mjs

View workflow job for this annotation

GitHub Actions / test (14.x)

'asyncWrap' is not defined

Check failure on line 7 in src/asyncForEachObject.mjs

View workflow job for this annotation

GitHub Actions / test (16.x)

'asyncWrap' is not defined

Check failure on line 7 in src/asyncForEachObject.mjs

View workflow job for this annotation

GitHub Actions / test (21.x)

'asyncWrap' is not defined
// 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
22 changes: 22 additions & 0 deletions src/asyncGroupBy.mjs
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

View workflow job for this annotation

GitHub Actions / test (20.x)

'Queue' is defined but never used

Check failure on line 4 in src/asyncGroupBy.mjs

View workflow job for this annotation

GitHub Actions / test (18.x)

'Queue' is defined but never used

Check failure on line 4 in src/asyncGroupBy.mjs

View workflow job for this annotation

GitHub Actions / test (22.x)

'Queue' is defined but never used

Check failure on line 4 in src/asyncGroupBy.mjs

View workflow job for this annotation

GitHub Actions / test (12.x)

'Queue' is defined but never used

Check failure on line 4 in src/asyncGroupBy.mjs

View workflow job for this annotation

GitHub Actions / test (14.x)

'Queue' is defined but never used

Check failure on line 4 in src/asyncGroupBy.mjs

View workflow job for this annotation

GitHub Actions / test (16.x)

'Queue' is defined but never used

Check failure on line 4 in src/asyncGroupBy.mjs

View workflow job for this annotation

GitHub Actions / test (21.x)

'Queue' is defined but never used

async function asyncGroupBy (iterable, iteratee, queueOrConcurrency = 1) {

Check warning on line 6 in src/asyncGroupBy.mjs

View workflow job for this annotation

GitHub Actions / test (20.x)

Missing JSDoc comment

Check warning on line 6 in src/asyncGroupBy.mjs

View workflow job for this annotation

GitHub Actions / test (18.x)

Missing JSDoc comment

Check warning on line 6 in src/asyncGroupBy.mjs

View workflow job for this annotation

GitHub Actions / test (22.x)

Missing JSDoc comment

Check warning on line 6 in src/asyncGroupBy.mjs

View workflow job for this annotation

GitHub Actions / test (12.x)

Missing JSDoc comment

Check warning on line 6 in src/asyncGroupBy.mjs

View workflow job for this annotation

GitHub Actions / test (14.x)

Missing JSDoc comment

Check warning on line 6 in src/asyncGroupBy.mjs

View workflow job for this annotation

GitHub Actions / test (16.x)

Missing JSDoc comment

Check warning on line 6 in src/asyncGroupBy.mjs

View workflow job for this annotation

GitHub Actions / test (21.x)

Missing JSDoc comment
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
}

0 comments on commit a931683

Please sign in to comment.