Comments (3)
I ended up putting in two examples - still illustrative, but hopefully a bit more helpful. Here's actually executable forms of the same examples similar to the mods you made:
var waterfall = require('async-waterfall');
var myArray = [1,2,3];
var myResult = 1;
waterfall(myArray.map(function (arrayItem) {
return function (nextCallback) {
myResult *= arrayItem;
nextCallback();
}}), function (err) {
console.log(myResult);
});
waterfall([function initializer (firstMapFunction) {
var initialValue = 1;
firstMapFunction(null, initialValue);
}].concat(myArray.map(function (arrayItem) {
return function (lastItemResult, nextCallback) {
var itemResult = arrayItem * lastItemResult;
nextCallback(null, itemResult);
}})), function (err, result) {
console.log(result);
});
from async-waterfall.
Yeah, it was really meant to be illustrative, but you're right, it ought to be a working example. The issue is that the first function is called without arguments (other than the callback). There are several ways to approach this, and I suppose I'll update the example with the simplest, which is to remove the function arguments and run the calculations on a variable declared outside the mapped closures.
Depending on the situation, other good approaches I can think of are to start off with an initializer function, or to duck-type the arguments within the mapped function.
from async-waterfall.
thanks!
from async-waterfall.
Related Issues (9)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from async-waterfall.