Skip to content

Reduce blows call stack #3

@wvl

Description

@wvl
var arr = [];
for (var i=0; i<=100000; i++) { arr.push(i) }
zo(arr).reduce(0, function(memo, item, into) {
  into(memo + item);
}).results(function(sum) {
  console.log("Sum", sum);
});

This will now blow the call stack, since reduce is recursive.

fwiw, I was looking at zo (which I hadn't seen before), because I was writing my own functional async library, and ran into the above problem. I just figured it out -- thanks to mikegerwitz on irc. If you use process.nextTick, you won't exhaust the call stack.

So, in your foldl, do:
process.nextTick(function() {
xyz(folded, index + 1, items, next);
})

Cheers

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions