Code Monkey home page Code Monkey logo

Comments (3)

es128 avatar es128 commented on June 3, 2024 1

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.

es128 avatar es128 commented on June 3, 2024

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.

Marketcentric avatar Marketcentric commented on June 3, 2024

thanks!

from async-waterfall.

Related Issues (9)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.