Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
The it-map npm package is a utility for transforming async iterables. It allows you to apply a mapping function to each item in an async iterable, similar to how Array.prototype.map works for arrays.
Basic Mapping
This feature allows you to apply a simple mapping function to each item in an async iterable. In this example, each number yielded by the async generator is doubled.
const itMap = require('it-map');
async function* asyncGenerator() {
yield 1;
yield 2;
yield 3;
}
const mapped = itMap(asyncGenerator(), x => x * 2);
(async () => {
for await (const value of mapped) {
console.log(value); // 2, 4, 6
}
})();
Async Mapping Function
This feature allows you to use an async function as the mapping function. In this example, each number is doubled after a 100ms delay.
const itMap = require('it-map');
async function* asyncGenerator() {
yield 1;
yield 2;
yield 3;
}
const mapped = itMap(asyncGenerator(), async x => {
await new Promise(resolve => setTimeout(resolve, 100));
return x * 2;
});
(async () => {
for await (const value of mapped) {
console.log(value); // 2, 4, 6
}
})();
The it-pipe package is used for creating pipelines of async iterables. It allows you to compose multiple transformations in a readable manner. Compared to it-map, it-pipe provides a more comprehensive solution for chaining multiple async iterable transformations.
The it-filter package is used for filtering items in async iterables. While it-map focuses on transforming each item, it-filter focuses on including or excluding items based on a predicate function. Both can be used together for more complex async iterable manipulations.
The it-take package is used for taking a specified number of items from an async iterable. This is useful for limiting the number of items processed, which can be combined with it-map for more controlled transformations.
Maps the values yielded by an async iterator
Convert one value from an (async)iterator into another.
import map from 'it-map'
// This can also be an iterator, generator, etc
const values = [0, 1, 2, 3, 4]
const result = map(values, (val, index) => val++)
console.info(result) // [1, 2, 3, 4, 5]
Async sources and transforms must be awaited:
import map from 'it-map'
const values = async function * () {
yield * [0, 1, 2, 3, 4]
}
const result = await map(values(), async (val, index) => val++)
console.info(result) // [1, 2, 3, 4, 5]
$ npm i it-map
<script>
tagLoading this module through a script tag will make it's exports available as ItMap
in the global namespace.
<script src="https://unpkg.com/it-map/dist/index.min.js"></script>
Licensed under either of
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
FAQs
Maps the values yielded by an async iterator
We found that it-map demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.