cheeky-async

Some cheeky async versions of Array methods like map, filter and reduce. With support for sequential and parallel processing.

Usage no npm install needed!

<script type="module">
  import cheekyAsync from 'https://cdn.skypack.dev/cheeky-async';
</script>

README

cheeky-async

package version package downloads standard-readme compliant package license make a pull request

Some cheeky async versions of Array methods like map, filter and reduce. With support for sequential and parallel processing.

Table of Contents

Usage

import {map} from "cheeky-async"

await map([1, 2, 3], async (value) => {
  return value + (await getThingy())
})

Install

This project uses node and npm.

$ npm install cheeky-async
$ # OR
$ yarn add cheeky-async

API

Table of Contents

map

Invoke an async transform/mapping function on each item in an Array returning the resulting Array of transformed/mapped items. Async async transform/mapping function is invoked in parallel by default.

This is an async version of Array.prototype.map().

Parameters

  • array Array The Array to map over
  • mapper MapperFunction Async function, gets passed (value, index, array), returns the new value.
  • config Config Configuration

filter

Invoke an async predicate function on each item in an Array returning the resulting Array with all items passing the condition of the predicate function. Async async predicate function is invoked in parallel by default.

This is an async version of Array.prototype.filter().

Parameters

  • array Array The Array to map over
  • mapper PredicateFunction Async function, gets passed (value, index, array), returns the new value.
  • config Config Configuration

Returns Promise resulting mapped/transformed values.

every

Invoke an async predicate function on each item in an Array returning true/false depending on all items passing the condition of the predicate function. Async async predicate function is invoked in parallel by default.

This is an async version of Array.prototype.every().

Parameters

  • array Array The Array to map over
  • mapper PredicateFunction Async function, gets passed (value, index, array), returns the new value.
  • config Config Configuration

Returns Promise<Boolean> resulting mapped/transformed values.

some

Invoke an async predicate function on each item in an Array returning true/false depending on any items passing the condition of the predicate function. Async async predicate function is invoked in parallel by default.

This is an async version of Array.prototype.some().

Parameters

  • array Array The Array to map over
  • mapper PredicateFunction Async function, gets passed (value, index, array), returns the new value.
  • config Config Configuration

Returns Promise<Boolean> resulting mapped/transformed values.

reduce

Invoke an async reducer function on each item in an Array returning the resulting value. Async async reducer function is invoked in sequence by default.

This is an async version of Array.prototype.reduce().

Parameters

  • array Array The Array to reduce.
  • reducer reducerFunction Async function, gets passed (accumulator, value, index, array), returns the new accumulator.
  • config Config Configuration

Returns Promise resulting value.

Contribute

  1. Fork it and create your feature branch: git checkout -b my-new-feature
  2. Commit your changes: git commit -am "Add some feature"
  3. Push to the branch: git push origin my-new-feature
  4. Submit a pull request

License

MIT