@promises/for-each-right-series
v0.5.0
Published
For Each Right Series is package from Promises library
Downloads
45
Maintainers
Readme
@promises/for-each-right-series
For Each Right Series is package from Promises library
Use
Module
$ npm install --save @promises/for-each-right-series
import {
default as forEachRightSeries
} from '@promises/for-each-right-series';
Browser
<script src="https://unpkg.com/@promises/for-each-right-series/bundle.umd.min.js"></script>
let {
forEachRightSeries
} = P;
Examples
let array: number[] = [3, 7, 1, 5];
console.log('before');
forEachRightSeries(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 5
// => end 5
// => start 1
// => end 1
// => start 7
// => end 7
// => start 3
// => end 3
// => complete
Functional programming
Module
$ npm install --save @promises/for-each-right-series
import {
__,
default as forEachRightSeries
} from '@promises/for-each-right-series/fp';
Browser
<script src="https://unpkg.com/@promises/for-each-right-series/fp/bundle.umd.min.js"></script>
let {
__,
forEachRightSeries
} = PF;
Examples
let array: number[] = [3, 7, 1, 5];
console.log('before');
forEachRightSeries((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 5
// => end 5
// => start 1
// => end 1
// => start 7
// => end 7
// => start 3
// => end 3
// => complete
Wrapper
Module
$ npm install --save @promises/for-each-right-series
import Promises from '@promises/core';
import '@promises/for-each-right-series/add';
Or
import Promises from '@promises/for-each-right-series/add';
Browser
<script src="https://unpkg.com/@promises/core/bundle.umd.min.js"></script>
<script src="https://unpkg.com/@promises/for-each-right-series/add/bundle.umd.min.js"></script>
let {
Promises
} = P;
Examples
let array: number[] = [3, 7, 1, 5];
let promises: Promises<number[]> = Promises.resolve(array);
console.log('before');
promises.forEachRightSeries((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 5
// => end 5
// => start 1
// => end 1
// => start 7
// => end 7
// => start 3
// => end 3
// => 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, Licensed under the MIT license.