npm package: @promises/for-each-series
Description: For Each Series is package from Promises library
Author: Yisrael Eliev
Latest version: 0.5.0



# @promises/for-each-series
[![Source Code](https://img.shields.io/badge/%3C%2F%3E-source_code-blue.svg)](https://github.com/yisraelx/promises/blob/master/modules/for-each-series)
[![Version](https://img.shields.io/npm/v/@promises/for-each-series.svg)](https://www.npmjs.com/package/@promises/for-each-series)
[![MIT License](https://img.shields.io/npm/l/@promises/for-each-series.svg)](https://github.com/yisraelx/promises/blob/master/LICENSE)
[![Bundle Size](https://img.shields.io/bundlephobia/min/@promises/for-each-series.svg)](https://bundlephobia.com/result?p=@promises/for-each-series)

**For Each Series is package from Promises library**

## Use

**Module**
```sh
$ npm install --save @promises/for-each-series
```
```typescript
import {
 default as forEachSeries
} from '@promises/for-each-series';
```

**Browser**
```html
<script src="https://unpkg.com/@promises/for-each-series/bundle.umd.min.js"></script>
```
```typescript
let {
 forEachSeries
} = P;
```


**Examples**
```typescript
 let array: number[] = [3, 7, 1, 5];

 console.log('before');

 forEachSeries(array, (value: number) => {
     console.log(`start: ${ value }`);

     return timeout((resolve) => {
         console.log(`end: ${ value }`);
         resolve();
     }, value);

 }).then(() => {
     console.log('complete');
 });

 console.log('after');

 // => before
 // => after
 // => start 3
 // => end 3
 // => start 7
 // => end 7
 // => start 1
 // => end 1
 // => start 5
 // => end 5
 // => complete
```


### Functional programming

**Module**
```sh
$ npm install --save @promises/for-each-series
```
```typescript
import {
 __,
 default as forEachSeries
} from '@promises/for-each-series/fp';
```

**Browser**
```html
<script src="https://unpkg.com/@promises/for-each-series/fp/bundle.umd.min.js"></script>
```
```typescript
let {
 __,
 forEachSeries
} = PF;
```


**Examples**
```typescript
 let array: number[] = [3, 7, 1, 5];

 console.log('before');

 forEachSeries(array, (value: number) => {
     console.log(`start: ${ value }`);

     return timeout((resolve) => {
         console.log(`end: ${ value }`);
         resolve();
     }, value);

 })(array).then(() => {
     console.log('complete');
 });

 console.log('after');

 // => before
 // => after
 // => start 3
 // => end 3
 // => start 7
 // => end 7
 // => start 1
 // => end 1
 // => start 5
 // => end 5
 // => complete
```


### Wrapper

**Module**
```sh
$ npm install --save @promises/for-each-series
```
```typescript
import Promises from '@promises/core';
import '@promises/for-each-series/add';
```
*Or*
```typescript
import Promises from '@promises/for-each-series/add';
```

**Browser**
```html
<script src="https://unpkg.com/@promises/core/bundle.umd.min.js"></script>
<script src="https://unpkg.com/@promises/for-each-series/add/bundle.umd.min.js"></script>
```
```typescript
let {
 Promises
} = P;
```


**Examples**
```typescript
 let array: number[] = [3, 7, 1, 5];
 let promises: Promises<number[]> = Promises.resolve(array);

 console.log('before');
 promises.forEachSeries((value: number) => {
     console.log(`start: ${ value }`);
     return timeout((resolve) => {
         console.log(`end: ${ value }`);
         resolve();
     }, value);
 }).then(() => {
     console.log('complete');
 });
 console.log('after');

 // => before
 // => after
 // => start 3
 // => end 3
 // => start 7
 // => end 7
 // => start 1
 // => end 1
 // => start 5
 // => end 5
 // => complete
```


## Compatibility
These modules are written in typescript and available in ES5 and ES6 standard, the requirements are a global __Promise__ (native or polyfill).

## License
Copyright © 2017 [Yisrael Eliav](https://github.com/yisraelx),
Licensed under the [MIT license](https://github.com/yisraelx/promises/blob/master/LICENSE).