Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/litichevskiydv/partitioned-loops
Library for partitioned loops organization
https://github.com/litichevskiydv/partitioned-loops
Last synced: 23 days ago
JSON representation
Library for partitioned loops organization
- Host: GitHub
- URL: https://github.com/litichevskiydv/partitioned-loops
- Owner: litichevskiydv
- License: mit
- Created: 2019-06-04T05:59:54.000Z (over 5 years ago)
- Default Branch: develop
- Last Pushed: 2023-01-19T04:00:16.000Z (about 2 years ago)
- Last Synced: 2024-04-26T18:21:27.116Z (9 months ago)
- Language: JavaScript
- Size: 460 KB
- Stars: 0
- Watchers: 0
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# partitioned-loops
[![npm version](https://badge.fury.io/js/partitioned-loops.svg)](https://www.npmjs.com/package/partitioned-loops)
[![npm downloads](https://img.shields.io/npm/dt/partitioned-loops.svg)](https://www.npmjs.com/package/partitioned-loops)
[![dependencies status](https://img.shields.io/librariesio/github/litichevskiydv/partitioned-loops)](https://www.npmjs.com/package/partitioned-loops)
[![Build Status](https://github.com/litichevskiydv/partitioned-loops/actions/workflows/ci.yaml/badge.svg?branch=master)](https://github.com/litichevskiydv/partitioned-loops/actions/workflows/ci.yaml)
[![Coverage Status](https://coveralls.io/repos/github/litichevskiydv/partitioned-loops/badge.svg?branch=master)](https://coveralls.io/github/litichevskiydv/partitioned-loops?branch=master)Library for partitioned loops organization
# Install
`npm i partitioned-loops`
# Usage
```javascript
const { forEachAsync } = require("partitioned-loops");/*...*/
const finalState = await forEachAsync(
[1, 2, 3, 4, 5],
(currentValue, loopState) => {
if (currentValue > 4) loopState.break = true;
else loopState.sum += currentValue;
},
{ sum: 0 }
);
``````javascript
const { forAsync } = require("partitioned-loops");/*...*/
const array = [1, 2, 3, 4, 5];
const finalState = await forAsync(
0,
array.length,
(i, loopState) => {
if (array[i] > 4) loopState.break = true;
else loopState.sum += array[i];
},
{ sum: 0 }
);
```