Skip to content

Latest commit

 

History

History
41 lines (28 loc) · 1.02 KB

filter.md

File metadata and controls

41 lines (28 loc) · 1.02 KB

npu.map

async function filter(
  input: Resolvable<Iterable<Resolvable<any>>>,
  filterer: (item: any, index: number, length: number) => Resolvable<any>,
  options?: {
    concurrency?: number = Infinity
  }
): Promise<any[]>

Given a finite Iterable (arrays are Iterable), or a promise of an Iterable, which produces promises (or a mix of promises and values), iterate over all the values in the Iterable into an array and filter the array to another using the given filterer function.

The input iterable is not modified.

Filter option: concurrency

See Map option: concurrency

Example

const npu = require('native-promise-util')

;(async () => {
  const input = [4, 5, 1, 3, 2].map(i => Promise.resolve(i))
  const output = await npu.filter(input, i => i > 2)
  // Print [ 4, 5, 3 ]
  console.log(output)
})()