Sequence.js

Possible errors

TypeError: undefined is not a function

That error might occur when you try to destruct an argument thats not an array but a function. Example:

let myFunc = ([arg1, arg2, arg3]) => {
    // ...
};
myFunc(function cb() {
    // ...
});

Why does this happen?
It happens when you create an array of step functions thats first or second argument is a destructing array and pass that array of step functions directly to sqnc.step() like this:

// this wont work:
let stepFunc = ([counter]) => {
    return counter + 1;
};
let arr = Array.from(Array(1000), (undefined, i) => { return stepFunc });
let sqnc = new Sequence();
sqnc.step(arr); // <-- source of error
sqnc.run([0]).then(([counter]) => { console.log(counter); });

What happens exactly?
sqnc.step() will check its argument.
Is it a function? Then it will be used as a wrapper for the argument return of previous steps. Otherwise it will be treated as a list of step items.

Each item will be checked for its type again:
Its a Promise? Call then() on it.
Its a child sequence? Call .run() on it.
Its a normal value? Forward it directly to next step.
Its a function? Check if it is using callback or return method by checking its expected arguments count. In this case the argument count of each step item function is 1 so its been treated as a function with callbacks. That function will then be called like: stepFunc(function resolve, function reject) and thats where the error occurs because function resolve cannot be destructed to [counter].

Workaround
Dont create a multi step (step with multiple items) but a single step for each function:

// this is OK:
let stepFunc = ([counter]) => {
    return counter + 1;
};
let arr = Array.from(Array(1000), (undefined, i) => { return stepFunc });
let sqnc = new Sequence();
arr.forEach(sqnc.step);
sqnc.run([0]).then(([counter]) => { console.log(counter); });