1.0.0 • Published 7 years ago
map-iter v1.0.0
map-iter
Applies a callback to each value outputted by an iterable.
Installation
Requires Node.js 6.0.0 or above.
npm i map-iterAPI
The module exports a single function.
Parameters
iter(iterable)cb(function): The callback that, for each value iterated byiter, will be given two arguments: the value iterated, and an incrementing index counter that starts at zero. The return value ofcbwill be iterated in lieu of the original value.
Return Value
An iterator that outputs the return values of cb.
Example
const map = require('map-iter')
const iterator = map([1, 2, 3], x => x * 2)
iterator.next().value // 2
iterator.next().value // 4
iterator.next().value // 6
iterator.next().done // trueRelated
- filter-iter: Filters an iterable object so that it only yields values which pass a test function.
- partition-iterable: Divides iterated values into those that match a filter and those that don’t.
- reduce-iterable: Applies a function to iterated values to reduce them to a single value.
- unique-iterable: Filters an iterable object so it doesn’t yield the same value more than once.
- unique-iterable-by: Filters yielded values by testing uniqueness with an index, key, or callback.
- @lamansky/every: Array.prototype.every() for iterables.
- @lamansky/some: Array.prototype.some() for iterables.
1.0.0
7 years ago