Global

Methods

all(array) → {Aigle}

Source:

Aigle.all is almost the same functionality as Promise.all. It will return an Aigle instance.

Example
const order = [];
const makeDelay = (num, delay) => {
  return Aigle.delay(delay)
    .then(() => {
      order.push(num);
      return num;
    });
};
Aigle.all([
  makeDelay(1, 30),
  makeDelay(2, 20),
  makeDelay(3, 10)
])
.then(array => {
  console.log(array); // [1, 2, 3];
  console.log(order); // [3, 2, 1];
});
Parameters:
Name Type Description
array Array
Returns:

Returns an Aigle instance

Type
Aigle

allSettled(collection)

Source:

Return an Aigle instance

Example
Aigle.allSettled([
  Aigle.resolve(1),
  Aigle.reject(2),
  Aigle.reject(3)
])
.then(array => {
  console.log(array); // [{ state: 'fulfilled', value: 1 }, { state: 'rejected', reason: 2 }, { state: 'rejected', reason: 3 }]
});
Parameters:
Name Type Description
collection Array | Object

it should be an array/object of functions or Promise instances

attempt(handler) → {Aigle}

Source:
Example
Aigle.attempt(() => {
    throw Error('error');
  })
  .catch(error => console.log(error)); // error
Parameters:
Name Type Description
handler function
Returns:

Returns an Aigle instance

Type
Aigle

concat(collection, iterator) → {Aigle}

Source:

Aigle.concat has almost the same functionality as Array#concat. It iterates all elements of collection and executes iterator using each element on parallel. The iterator needs to return a promise or something. If a promise is returned, the function will wait until the promise is fulfilled. Then the result will be assigned to an array, the role is the same as Array#concat. All of them are finished, the function will return an array as a result.

Examples
const order = [];
const collection = [1, 4, 2];
const iterator = (num, index, collection) => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return num;
    });
};
Aigle.concat(collection, iterator)
  .then(array => {
    console.log(array); // [1, 2, 4];
    console.log(order); // [1, 2, 4];
  });
const order = [];
const collection = { a: 1, b: 4, c: 2 };
const iterator = (num, key, collection) => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return num;
    });
};
Aigle.concat(collection, iterator)
  .then(array => {
    console.log(array); // [1, 2, 4];
    console.log(order); // [1, 2, 4];
  });
Parameters:
Name Type Description
collection Array | Object
iterator function
Returns:

Returns an Aigle instance

Type
Aigle

concatLimit(collection, limitopt, iterator) → {Aigle}

Source:

Aigle.concatLimit is almost the as Aigle.concat and Aigle.concatSeries, but it will work with concurrency.

Examples
const order = [];
const collection = [1, 5, 3, 4, 2];
const iterator = (num, index, collection) => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return num;
    });
};
Aigle.concatLimit(collection, 2, iterator)
  .then(array => {
    console.log(array); // [1, 3, 5, 2, 4];
    console.log(order); // [1, 3, 5, 2, 4];
  });
const order = [];
const collection = {
  task1: 1,
  task2: 5,
  task3: 3,
  task4: 4,
  task5: 2
};
const iterator = (num, key, collection) => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return num;
    });
};
Aigle.concatLimit(collection, 2, iterator)
  .then(array => {
    console.log(array); // [1, 3, 5, 2, 4];
    console.log(order); // [1, 3, 5, 2, 4];
  });
const order = [];
const collection = [1, 5, 3, 4, 2];
const iterator = num => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return num;
    });
};
Aigle.concatLimit(collection, iterator)
  .then(array => {
    console.log(array); // [1, 2, 3, 4, 5];
    console.log(order); // [1, 2, 3, 4, 5];
  });
Parameters:
Name Type Attributes Default Description
collection Array | Object
limit integer <optional>
8
iterator function
Returns:

Returns an Aigle instance

Type
Aigle

concatSeries(collection, iterator) → {Aigle}

Source:

Aigle.concatSeries is almost the as Aigle.concat, but it will work in series.

Examples
const order = [];
const collection = [1, 4, 2];
const iterator = (num, index, collection) => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return num;
    });
};
Aigle.concatSeries(collection, iterator)
  .then(array => {
    console.log(array); // [1, 4, 2];
    console.log(order); // [1, 4, 2];
  });
const order = [];
const collection = { a: 1, b: 4, c: 2 };
const iterator = (num, key, collection) => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return num;
    });
};
Aigle.concatSeries(collection, iterator)
  .then(array => {
    console.log(array); // [1, 4, 2];
    console.log(order); // [1, 4, 2];
  });
Parameters:
Name Type Description
collection Array | Object
iterator function
Returns:

Returns an Aigle instance

Type
Aigle

config(opts)

Source:
Parameters:
Name Type Description
opts Object
Properties
Name Type Attributes Description
longStackTraces boolean <optional>
cancellation boolean <optional>

delay(ms, value) → {Aigle}

Source:

Return a promise which will be resolved with value after ms.

Examples
Aigle.delay(10)
  .then(value => console.log(value); // undefined
Aigle.delay(10, 'test')
  .then(value => console.log(value); // 'test'
Parameters:
Name Type Description
ms number
value *
Returns:

Returns an Aigle instance

Type
Aigle

doUntil(valueopt, iterator, tester) → {Aigle}

Source:
Examples
let count = 0;
const order = [];
const tester = num => {
  order.push(`t:${num}`);
  return Aigle.delay(10)
    .then(() => num === 4);
};
const iterator = () => {
  const num = ++count;
  order.push(`i:${num}`);
  return Aigle.delay(10)
    .then(() => num);
};
Aigle.doUntil(iterator, tester)
  .then(value => {
    console.log(value); // 4
    console.log(count); // 4
    console.log(order); // [ 'i:1', 't:1', 'i:2', 't:2', 'i:3', 't:3', 'i:4', 't:4' ]
  });
const order = [];
const tester = num => {
  order.push(`t:${num}`);
  return Aigle.delay(10)
    .then(() => num === 4);
};
const iterator = count => {
  const num = ++count;
  order.push(`i:${num}`);
  return Aigle.delay(10)
    .then(() => num);
};
Aigle.doUntil(0, iterator, tester)
  .then(value => {
    console.log(value); // 4
    console.log(order); // [ 'i:1', 't:1', 'i:2', 't:2', 'i:3', 't:3', 'i:4', 't:4' ]
  });
Parameters:
Name Type Attributes Description
value * <optional>
iterator function
tester function
Returns:

Returns an Aigle instance

Type
Aigle

doWhilst(valueopt, iterator, tester) → {Aigle}

Source:
Examples
let count = 0;
const order = [];
const tester = num => {
  order.push(`t:${num}`);
  return Aigle.delay(10)
    .then(() => num !== 4);
};
const iterator = () => {
  const num = ++count;
  order.push(`i:${num}`);
  return Aigle.delay(10)
    .then(() => num);
};
Aigle.doWhilst(iterator, tester)
  .then(value => {
    console.log(value); // 4
    console.log(count); // 4
    console.log(order); // [ 'i:1', 't:1', 'i:2', 't:2', 'i:3', 't:3', 'i:4', 't:4' ]
  });
const order = [];
const tester = num => {
  order.push(`t:${num}`);
  return Aigle.delay(10)
    .then(() => num !== 4);
};
const iterator = count => {
  const num = ++count;
  order.push(`i:${num}`);
  return Aigle.delay(10)
    .then(() => num);
};
Aigle.doWhilst(0, iterator, tester)
  .then(value => {
    console.log(value); // 4
    console.log(order); // [ 'i:1', 't:1', 'i:2', 't:2', 'i:3', 't:3', 'i:4', 't:4' ]
  });
Parameters:
Name Type Attributes Description
value * <optional>
iterator function
tester function
Returns:

Returns an Aigle instance

Type
Aigle

each(iterator)

Source:
Parameters:
Name Type Description
iterator function

each(collection, iterator) → {Aigle}

Source:

Aigle.each iterates all elements of collection and execute iterator for each element on parallel. The iterator is called with three arguments. (value, index|key, collection) If the iterator returns false or a promise which has false as a result, the promise state will be onFulfilled immediately. ⚠ All elements are already executed and can't be stopped. If you care about it, you should use Aigle.eachSeries.

Examples
const order = [];
  const collection = [1, 4, 2];
  const iterator = (num, index, collection) => {
    return Aigle.delay(num * 10)
      .then(() => order.push(num));
  };
  return Aigle.each(collection, iterator)
    .then(value => {
      console.log(value); // undefined
      console.log(order); // [1, 2, 4];
    });
const order = [];
  const collection = { a: 1, b: 4, c: 2 };
  const iterator = (num, key, collection) => {
    return Aigle.delay(num * 10)
      .then(() => order.push(num));
  };
  return Aigle.each(collection, iterator)
    .then(value => {
      console.log(value); // undefined
      console.log(order); // [1, 2, 4];
    });
const order = [];
   const collection = [1, 4, 2];
   const iterator = (num, index, collection) => {
     return Aigle.delay(num * 10)
       .then(() => {
         order.push(num);
         return num !== 2; // break
       });
   };
   return Aigle.each(collection, iterator)
     .then(value => {
       console.log(value); // undefined
       console.log(order); // [1, 2];
     });
Parameters:
Name Type Description
collection Array | Object
iterator function
Returns:

Returns an Aigle instance

Type
Aigle

eachLimit(limitopt, iterator)

Source:
Parameters:
Name Type Attributes Default Description
limit number <optional>
8
iterator function

eachLimit(A, limitopt, iterator) → {Aigle}

Source:

Aigle.eachLimit is almost same as Aigle.each and Aigle.eachSeries, but it will work with concurrency. limit is concurrency, if it is not defined, concurrency is 8.

Examples
const order = [];
const collection = [1, 5, 3, 4, 2];
const iterator = (num, index) => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return num;
    });
};
Aigle.eachLimit(collection, 2, iterator)
  .then(value => {
    console.log(value); // undefined
    console.log(order); // [1, 3, 5, 2, 4];
  });
const order = [];
const collection = {
  task1: 1,
  task2: 5,
  task3: 3,
  task4: 4,
  task5: 2
};
const iterator = (num, key) => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return num;
    });
};
Aigle.eachLimit(collection, 2, iterator)
  .then(value => {
    console.log(value); // undefined
    console.log(order); // [1, 3, 5, 2, 4];
  });
const order = [];
const collection = [1, 5, 3, 4, 2];
const iterator = num => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return num;
    });
};
Aigle.eachLimit(collection, iterator)
  .then(value => {
    console.log(value); // undefined
    console.log(order); // [1, 2, 3, 4, 5];
  });
const order = [];
const collection = [1, 5, 3, 4, 2];
const iterator = num => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return num !== 3;
    });
};
Aigle.eachLimit(collection, iterator)
  .then(value => {
    console.log(value); // undefined
    console.log(order); // [1, 2, 3];
  });
Parameters:
Name Type Attributes Default Description
A Array | Object

collection to iterate over

limit integer <optional>
8

It is concurrncy, default is 8

iterator function
Returns:

Returns an Aigle instance

Type
Aigle

eachSeries(iterator)

Source:
Parameters:
Name Type Description
iterator function

eachSeries(collection, iterator) → {Aigle}

Source:

Aigle.eachSeries is almost the same as Aigle.each, but it will work in series.

Examples
const order = [];
const collection = [1, 4, 2];
const iterator = num => {
  return Aigle.delay(num * 10)
    .then(() => order.push(num));
};
Aigle.eachSeries(collection, iterator)
  .then(value => {
    console.log(value); // undefined
    console.log(order); // [1, 4, 2];
  });
const order = [];
const collection = { a: 1, b: 4, c: 2 };
const iterator = num => {
  return Aigle.delay(num * 10)
    .then(() => order.push(num));
};
Aigle.eachSeries(collection, iterator)
  .then(value => {
    console.log(value); // undefined
    console.log(order); // [1, 4, 2];
  });
const order = [];
const collection = [1, 4, 2];
const iterator = num => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return num !== 4; // break
    });
};
Aigle.eachSeries(collection, iterator)
  .then(value => {
    console.log(value); // undefined
    console.log(order); // [1, 4];
  });
Parameters:
Name Type Description
collection Array | Object
iterator function
Returns:

Returns an Aigle instance

Type
Aigle

every(collection, iterator) → {Aigle}

Source:

Aigle.every is similar to Array#every. If all elements return truthly or a promise which has a truthly value as a result, the result will be true, otherwise it will be false.

Examples
const order = [];
const collection = [1, 4, 2];
const iterator = (num, index, collection) => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return true;
    });
};
Aigle.every(collection, iterator)
  .then(value => {
    console.log(value); // true
    console.log(order); // [1, 2, 4];
  });
const order = [];
const collection = { a: 1, b: 4, c: 2 };
const iterator = (num, key, collection) => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return true;
    });
};
Aigle.every(collection, iterator)
  .then(value => {
    console.log(value); // true
    console.log(order); // [1, 2, 4];
  });
const order = [];
const collection = [1, 4, 2];
const iterator = num => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return n % 2;
    });
};
Aigle.every(collection, iterator)
  .then(value => {
    console.log(value); // false
    console.log(order); // [1, 2];
  });
const collection = [{
 uid: 1, active: false
}, {
 uid: 4, active: true
}, {
 uid: 2, active: true
}];
Aigle.every(collection, 'active')
  .then(value => console.log(value)); // false
const collection = [{
 uid: 1, active: false
}, {
 uid: 4, active: true
}, {
 uid: 2, active: true
}];
Aigle.every(collection, ['active', true])
  .then(value => console.log(value)); // false
const collection = [{
 uid: 1, active: true
}, {
 uid: 4, active: true
}, {
 uid: 2, active: true
}];
Aigle.every(collection, { active: true })
  .then(value => console.log(value)); // true
Parameters:
Name Type Description
collection Array | Object
iterator function | Array | Object | string
Returns:

Returns an Aigle instance

Type
Aigle

everyLimit(collection, limitopt, iterator) → {Aigle}

Source:
Examples
const order = [];
const collection = [1, 5, 3, 4, 2];
const iterator = (num, index) => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return true;
    });
};
Aigle.everyLimit(collection, 2, iterator)
  .then(value => {
    console.log(value); // true
    console.log(order); // [1, 3, 5, 2, 4];
  });
const order = [];
const collection = {
  task1: 1,
  task2: 5,
  task3: 3,
  task4: 4,
  task5: 2
};
const iterator = (num, key) => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return true;
    });
};
Aigle.everyLimit(collection, 2, iterator)
  .then(value => {
    console.log(value); // true
    console.log(order); // [1, 3, 5, 2, 4];
  });
const order = [];
const collection = [1, 5, 3, 4, 2];
const iterator = num => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return num === 4;
    });
};
Aigle.everyLimit(collection, iterator)
  .then(value => {
    console.log(value); // false
    console.log(order); // [1, 2, 3, 4];
  });
Parameters:
Name Type Attributes Default Description
collection Array | Object
limit integer <optional>
8
iterator function
Returns:

Returns an Aigle instance

Type
Aigle

everySeries(collection, iterator) → {Aigle}

Source:

Aigle.everySeries is almost the same as Aigle.every, but it will work in series.

Examples
const order = [];
const collection = [1, 4, 2];
const iterator = (num, index, collection) => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return true;
    });
};
Aigle.everySeries(collection, iterator)
  .then(value => {
    console.log(value); // true
    console.log(order); // [1, 4, 2];
  });
const order = [];
const collection = { a: 1, b: 4, c: 2 };
const iterator = (num, key, collection) => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return true;
    });
};
Aigle.everySeries(collection, iterator)
  .then(value => {
    console.log(value); // true
    console.log(order); // [1, 4, 2];
  });
const order = [];
const collection = [1, 4, 2];
const iterator = num => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return n % 2;
    });
};
Aigle.everySeries(collection, iterator)
  .then(value => {
    console.log(value); // false
    console.log(order); // [1, 4];
  });
Parameters:
Name Type Description
collection Array | Object
iterator function
Returns:

Returns an Aigle instance

Type
Aigle

filter(collection, iterator) → {Aigle}

Source:

Aigle.filter has almost the same functionality as Array#filter. It iterates all elements of collection and executes iterator using each element on parallel. The iterator needs to return a promise or something. If a promise is returned, the function will wait until the promise is fulfilled. If the result is falsy, the element will be removed. All of them are finished, the function will return an array as a result.

Examples
const order = [];
const collection = [1, 4, 2];
const iterator = (num, index) => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return num % 2;
    });
};
Aigle.filter(collection, iterator)
  .then(array => {
    console.log(array); // [1];
    console.log(order); // [1, 2, 4];
  });
const order = [];
const collection = { a: 1, b: 4, c: 2 };
const iterator = (num, key) => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return num % 2;
    });
};
Aigle.filter(collection, iterator)
  .then(array => {
    console.log(array); // [1];
    console.log(order); // [1, 2, 4];
  });
const order = [];
const collection = [{
  name: 'bargey', active: false
}, {
  name: 'fread', active: true
}];
Aigle.filter(collection, 'active')
  .then(array => {
    console.log(array); // [{ name: 'fread', active: true }]
  });
const order = [];
const collection = [{
  name: 'bargey', active: false
}, {
  name: 'fread', active: true
}];
Aigle.filter(collection, ['name', 'fread'])
  .then(array => {
    console.log(array); // [{ name: 'fread', active: true }]
  });
const order = [];
const collection = [{
  name: 'bargey', active: false
}, {
  name: 'fread', active: true
}];
Aigle.filter(collection, { name: 'fread', active: true })
  .then(array => {
    console.log(array); // [{ name: 'fread', active: true }]
  });
Parameters:
Name Type Description
collection Array | Object
iterator function | Array | Object | string
Returns:

Returns an Aigle instance

Type
Aigle

filterLimit(collection, limitopt, iterator) → {Aigle}

Source:

Aigle.filterLimit is almost the as Aigle.filter and Aigle.filterSeries, but it will work with concurrency.

Examples
const order = [];
const collection = [1, 5, 3, 4, 2];
const iterator = (num, index) => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return num % 2;
    });
};
Aigle.filterLimit(collection, 2, iterator)
  .then(array => {
    console.log(array); // [1, 5, 3];
    console.log(order); // [1, 3, 5, 2, 4];
  });
const order = [];
const collection = {
  task1: 1,
  task2: 5,
  task3: 3,
  task4: 4,
  task5: 2
};
const iterator = (num, key) => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return num % 2;
    });
};
Aigle.filterLimit(collection, 2, iterator)
  .then(array => {
    console.log(array); // [1, 5, 3];
    console.log(order); // [1, 3, 5, 2, 4];
  });
const order = [];
const collection = [1, 5, 3, 4, 2];
const iterator = num => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return num % 2;
    });
};
Aigle.filterLimit(collection, iterator)
  .then(array => {
    console.log(array); // [1, 5, 3];
    console.log(order); // [1, 2, 3, 4, 5];
  });
Parameters:
Name Type Attributes Default Description
collection Array | Object
limit integer <optional>
8
iterator function
Returns:

Returns an Aigle instance

Type
Aigle

filterSeries(collection, iterator) → {Aigle}

Source:

Aigle.filterSeries is almost the as Aigle.filter, but it will work in series.

Examples
const order = [];
const collection = [1, 4, 2];
const iterator = (num, index) => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return num % 2;
    });
};
Aigle.filterSeries(collection, iterator)
  .then(array => {
    console.log(array); // [1];
    console.log(order); // [1, 4, 2];
  });
const order = [];
const collection = { a: 1, b: 4, c: 2 };
const iterator = (num, key) => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return num % 2;
    });
};
Aigle.filterSeries(collection, iterator)
  .then(array => {
    console.log(array); // [1];
    console.log(order); // [1, 4, 2];
  });
Parameters:
Name Type Description
collection Array | Object
iterator function
Returns:

Returns an Aigle instance

Type
Aigle

find(collection, iterator) → {Aigle}

Source:

Aigle.find has almost the same functionality as Array#find. It iterates all elements of collection and executes iterator using each element on parallel. The iterator needs to return a promise or something. If a promise is returned, the function will wait until the promise is fulfilled. If the result is truthly, the element will be returned as a result.

Examples
const order = [];
const collection = [1, 4, 2];
const iterator = num => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return num % 2 === 0;
    });
};
Aigle.find(collection, iterator)
  .then(value => {
    console.log(value); // 2
    console.log(order); // [1, 2]
  });
const order = [];
const collection = { a: 1, b: 4, c: 2 };
const iterator = num => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return num % 2 === 0;
    });
};
Aigle.find(collection, iterator)
  .then(value => {
    console.log(value); // 2
    console.log(order); // [1, 2]
  });
const order = [];
const collection = [1, 4, 2];
const iterator = num => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return false;
    });
};
Aigle.find(collection, iterator)
  .then(value => {
    console.log(value); // undefined
    console.log(order); // [1, 2, 4]
  });
const collection = [{
  name: 'bargey', active: false
}, {
  name: 'fread', active: true
}];
Aigle.find(collection, 'active')
  .then(object => {
    console.log(object); // { name: 'fread', active: true }
  });
const collection = [{
  name: 'bargey', active: false
}, {
  name: 'fread', active: true
}];
Aigle.find(collection, ['name', 'fread'])
  .then(object => {
    console.log(object); // { name: 'fread', active: true }
  });
const collection = [{
  name: 'bargey', active: false
}, {
  name: 'fread', active: true
}];
Aigle.find(collection, { name: 'fread', active: true })
  .then(object => {
    console.log(object); // { name: 'fread', active: true }
  });
Parameters:
Name Type Description
collection Array | Object
iterator function | Array | Object | string
Returns:

Returns an Aigle instance

Type
Aigle

findIndex(collection, iterator) → {Aigle}

Source:

Aigle.findIndex is like Aigle.find, it will return the index of the first element which the iterator returns truthy.

Examples
const order = [];
const collection = [1, 4, 2];
const iterator = num => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return num % 2 === 0;
    });
};
Aigle.findIndex(collection, iterator)
  .then(index => {
    console.log(index); // 2
    console.log(order); // [1, 2]
  });
const order = [];
const collection = [1, 4, 2];
const iterator = num => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return false;
    });
};
Aigle.findIndex(collection, iterator)
  .then(index => {
    console.log(index); // -1
    console.log(order); // [1, 2, 4]
  });
const collection = [{
  name: 'bargey', active: false
}, {
  name: 'fread', active: true
}];
Aigle.findIndex(collection, 'active')
  .then(index => {
    console.log(index); // 1
  });
const collection = [{
  name: 'bargey', active: false
}, {
  name: 'fread', active: true
}];
Aigle.findIndex(collection, ['name', 'fread'])
  .then(index => {
    console.log(index); // true
  });
const collection = [{
  name: 'bargey', active: false
}, {
  name: 'fread', active: true
}];
Aigle.find(collection, { name: 'fread', active: true })
  .then(index => {
    console.log(index); // 1
  });
Parameters:
Name Type Description
collection Array
iterator function | Array | Object | string
Returns:

Returns an Aigle instance

Type
Aigle

findIndexLimit(collection, limitopt, iterator) → {Aigle}

Source:

Aigle.findIndexLimit is almost the as Aigle.findIndex and Aigle.findIndexSeries, but it will work with concurrency.

Examples
const order = [];
const collection = [1, 5, 3, 4, 2];
const iterator = (num, index) => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return num % 2 === 0;
    });
};
Aigle.findIndexLimit(collection, 2, iterator)
  .then(index => {
    console.log(index); // 4
    console.log(order); // [1, 3, 5, 2];
  });
const order = [];
const collection = [1, 5, 3, 4, 2];
const iterator = num => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return num % 2 === 0;
    });
};
Aigle.findIndexLimit(collection, iterator)
  .then(index => {
    console.log(index); // 4
    console.log(order); // [1, 2];
  });
Parameters:
Name Type Attributes Default Description
collection Array
limit integer <optional>
8
iterator function
Returns:

Returns an Aigle instance

Type
Aigle

findIndexSeries(collection, iterator) → {Aigle}

Source:

Aigle.findIndexSeries is almost the as Aigle.findIndex, but it will work in series.

Examples
const order = [];
const collection = [1, 4, 2];
const iterator = num => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return num % 2 === 0;
    });
};
Aigle.findIndexSeries(collection, iterator)
  .then(index => {
    console.log(index); // 1
    console.log(order); // [1, 4];
  });
const order = [];
const collection = [1, 4, 2];
const iterator = num => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return false;
    });
};
Aigle.findIndexSeries(collection, iterator)
  .then(index => {
    console.log(index); // -1
    console.log(order); // [1, 4, 2];
  });
Parameters:
Name Type Description
collection Array
iterator function
Returns:

Returns an Aigle instance

Type
Aigle

findKey(collection, iterator) → {Aigle}

Source:
Parameters:
Name Type Description
collection Array | Object
iterator function | Array | Object | string
Returns:

Returns an Aigle instance

Type
Aigle

findKeyLimit(collection, limitopt, iterator) → {Aigle}

Source:
Parameters:
Name Type Attributes Default Description
collection Array | Object
limit integer <optional>
8
iterator function
Returns:

Returns an Aigle instance

Type
Aigle

findKeySeries(collection, iterator) → {Aigle}

Source:
Parameters:
Name Type Description
collection Array | Object
iterator function
Returns:

Returns an Aigle instance

Type
Aigle

findLimit(collection, limitopt, iterator) → {Aigle}

Source:

Aigle.findLimit is almost the as Aigle.find and Aigle.findSeries, but it will work with concurrency.

Examples
const order = [];
const collection = [1, 5, 3, 4, 2];
const iterator = (num, index) => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return num % 2 === 0;
    });
};
Aigle.findLimit(collection, 2, iterator)
  .then(value => {
    console.log(value); // 2
    console.log(order); // [1, 3, 5, 2];
  });
const order = [];
const collection = { a: 1, b: 5, c: 3, d: 4, e: 2 };
const iterator = (num, key) => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return num % 2 === 0;
    });
};
Aigle.findLimit(collection, 2, iterator)
  .then(value => {
    console.log(value); // 2
    console.log(order); // [1, 3, 5, 2];
  });
const order = [];
const collection = [1, 5, 3, 4, 2];
const iterator = num => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return num % 2 === 0;
    });
};
Aigle.findLimit(collection, iterator)
  .then(value => {
    console.log(value); // 2
    console.log(order); // [1, 2];
  });
Parameters:
Name Type Attributes Default Description
collection Array | Object
limit integer <optional>
8
iterator function
Returns:

Returns an Aigle instance

Type
Aigle

findSeries(collection, iterator) → {Aigle}

Source:

Aigle.findSeries is almost the as Aigle.find, but it will work in series.

Examples
const order = [];
const collection = [1, 4, 2];
const iterator = num => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return num % 2 === 0;
    });
};
Aigle.findSeries(collection, iterator)
  .then(value => {
    console.log(value); // 4
    console.log(order); // [1, 4];
  });
const order = [];
const collection = { a: 1, b: 4, c: 2 };
const iterator = num => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return num % 2 === 0;
    });
};
Aigle.findSeries(collection, iterator)
  .then(value => {
    console.log(value); // 4
    console.log(order); // [1, 4];
  });
const order = [];
const collection = [1, 4, 2];
const iterator = num => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return false;
    });
};
Aigle.findSeries(collection, iterator)
  .then(value => {
    console.log(value); // undefined
    console.log(order); // [1, 4, 2];
  });
Parameters:
Name Type Description
collection Array | Object
iterator function
Returns:

Returns an Aigle instance

Type
Aigle

flow(…funcs) → {function}

Source:
Example
const add = (a, b) => Aigle.delay(10, a + b);
  const square = n => Aigle.delay(10, n * n);
  const addSquare = Aigle.flow(add, square);
  return addSquare(1, 2).then(value => {
    console.log(value); // 9
  });
Parameters:
Name Type Attributes Description
funcs Array.<function()> <repeatable>
Returns:

Returns the new composite function

Type
function

groupBy(collection, iterator) → {Aigle}

Source:
Examples
const order = [];
const collection = [1, 4, 2];
const iterator = (num, index) => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return num % 2;
    });
};
Aigle.groupBy(collection, iterator)
  .then(object => {
    console.log(object); // { '0': [2, 4], '1': [1] };
    console.log(order); // [1, 2, 4];
  });
const order = [];
const collection = { a: 1, b: 4, c: 2 };
const iterator = (num, key) => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return num % 2;
    });
};
Aigle.groupBy(collection, iterator)
  .then(object => {
    console.log(object); // { '0': [2, 4], '1': [1] };
    console.log(order); // [1, 2, 4];
  });
const order = [];
const collection = ['one', 'two', 'three'];
Aigle.groupBy(collection, 'length')
  .then(object => {
    console.log(object); // { '3': ['one', 'two'], '5': ['three'] };
  });
const collection = [{
  name: 'bargey', active: false
}, {
  name: 'fread', active: true
}];
Aigle.groupBy(collection, ['active', true])
  .then(object => {
    console.log(object);
    // { 'true': [{ name: 'fread', active: true }], 'false': [{ name: 'bargey', active: false }];
  });
const collection = [{
  name: 'bargey', active: false
}, {
  name: 'fread', active: true
}];
Aigle.groupBy(collection, { active: true })
  .then(object => {
    console.log(object);
    // { 'true': [{ name: 'fread', active: true }], 'false': [{ name: 'bargey', active: false }];
  });
Parameters:
Name Type Description
collection Array | Object
iterator function | string
Returns:

Returns an Aigle instance

Type
Aigle

groupByLimit(collection, limitopt, iterator) → {Aigle}

Source:
Examples
const order = [];
const collection = [1, 5, 3, 4, 2];
const iterator = (num, index) => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return num % 2;
    });
};
Aigle.groupByLimit(collection, 2, iterator)
  .then(object => {
    console.log(object); // { '0': [2, 4], '1': [1, 3, 5] };
    console.log(order); // [1, 3, 5, 2, 4];
  });
const order = [];
const collection = {
  task1: 1,
  task2: 5,
  task3: 3,
  task4: 4,
  task5: 2
};
const iterator = (num, key) => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return num % 2;
    });
};
Aigle.groupByLimit(collection, 2, iterator)
  .then(object => {
    console.log(object); // { '0': [2, 4], '1': [1, 3, 5] };
    console.log(order); // [1, 3, 5, 2, 4];
  });
const order = [];
const collection = [1, 5, 3, 4, 2];
const iterator = num => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return num % 2;
    });
};
Aigle.groupByLimit(collection, iterator)
  .then(object => {
    console.log(object); // { '0': [2, 4], '1': [1, 3, 5] };
    console.log(order); // [1, 2, 3, 4, 5];
  });
Parameters:
Name Type Attributes Default Description
collection Array | Object
limit integer <optional>
8
iterator function
Returns:

Returns an Aigle instance

Type
Aigle

groupBySeries(collection, iterator) → {Aigle}

Source:
Examples
const order = [];
const collection = [1, 4, 2];
const iterator = (num, index) => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return num % 2;
    });
};
Aigle.groupBySeries(collection, iterator)
  .then(object => {
    console.log(object); // { '0': [4, 2], '1': [1] };
    console.log(order); // [1, 4, 2];
  });
const order = [];
const collection = { a: 1, b: 4, c: 2 };
const iterator = (num, key) => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return num % 2;
    });
};
Aigle.groupBySeries(collection, iterator)
  .then(object => {
    console.log(object); // { '0': [4, 2], '1': [1] };
    console.log(order); // [1, 4, 2];
  });
Parameters:
Name Type Description
collection Array | Object
iterator function
Returns:

Returns an Aigle instance

Type
Aigle

join()

Source:
Example
const p1 = Aigle.delay(20).then(() => 1);
const p2 = Aigle.delay(10).then(() => 2);
Aigle.join(p1, p2, (v1, v2) => {
  console.log(v1, v2); // 1 2
});

map(collection, iterator) → {Aigle}

Source:

Aigle.map has almost the same functionality as Array#map. It iterates all elements of collection and executes iterator using each element on parallel. The iterator needs to return a promise or something. Then the result will be assigned to an array and the array order will be ensured. All of them are finished, the function will return an array as a result.

Examples
const order = [];
const collection = [1, 4, 2];
const iterator = num => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return num * 2;
    });
};
Aigle.map(collection, iterator)
  .then(array => {
    console.log(array); // [2, 8, 4];
    console.log(order); // [1, 2, 4];
  });
const order = [];
const collection = { a: 1, b: 4, c: 2 };
const iterator = num => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return num * 2;
    });
};
Aigle.map(collection, iterator)
  .then(array => {
    console.log(array); // [2, 8, 4];
    console.log(order); // [1, 2, 4];
  });
const collection = [{
 uid: 1, name: 'test1'
}, {
 uid: 4, name: 'test4'
}, {
 uid: 2, name: 'test2'
}];
Aigle.map(collection, 'uid')
  .then(uids => console.log(uids)); // [1, 4, 2]
Parameters:
Name Type Description
collection Array | Object
iterator function | string
Returns:

Returns an Aigle instance

Type
Aigle

mapLimit(collection, limitopt, iterator) → {Aigle}

Source:

Aigle.mapLimit is almost the smae as Aigle.map and Aigle.mapSeries, but it will work with concurrency.

Examples
const order = [];
const collection = [1, 5, 3, 4, 2];
const iterator = (num, index) => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return num * 2;
    });
};
Aigle.mapLimit(collection, 2, iterator)
  .then(array => {
    console.log(array); // [2, 10, 6, 8, 4];
    console.log(order); // [1, 3, 5, 2, 4];
  });
const order = [];
const collection = { a: 1, b: 5, c: 3, d: 4, e: 2 };
const iterator = (num, key) => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return num * 2;
    });
};
Aigle.mapLimit(collection, 2, iterator)
  .then(array => {
    console.log(array); // [2, 10, 6, 8, 4];
    console.log(order); // [1, 3, 5, 2, 4];
  });
const order = [];
const collection = [1, 5, 3, 4, 2];
const iterator = num => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return num * 2;
    });
};
Aigle.mapLimit(collection, iterator)
  .then(array => {
    console.log(array); // [2, 10, 6, 8, 4];
    console.log(order); // [1, 2, 3, 4, 5];
  });
Parameters:
Name Type Attributes Default Description
collection Array | Object
limit integer <optional>
8
iterator function
Returns:

Returns an Aigle instance

Type
Aigle

mapSeries(collection, iterator) → {Aigle}

Source:

Aigle.mapSeries is almost the smae as Aigle.map, but it will work in series.

Examples
const order = [];
const collection = [1, 4, 2];
const iterator = num => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return num * 2;
    });
};
Aigle.mapSeries(collection, iterator)
  .then(array => {
    console.log(array); // [2, 8, 4];
    console.log(order); // [1, 4, 2];
  });
const order = [];
const collection = { a: 1, b: 4, c: 2 };
const iterator = num => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return num * 2;
    });
};
Aigle.mapSeries(collection, iterator)
  .then(array => {
    console.log(array); // [2, 8, 4];
    console.log(order); // [1, 4, 2];
  });
Parameters:
Name Type Description
collection Array | Object
iterator function
Returns:

Returns an Aigle instance

Type
Aigle

mapValues(collection, iterator) → {Aigle}

Source:

Aigle.mapValues is similar to Aigle.map. It returns an object instead of an array.

Examples
const order = [];
const collection = [1, 4, 2];
const iterator = num => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return num * 2;
    });
};
Aigle.mapValues(collection, iterator)
  .then(object => {
    console.log(object); // { '0': 2, '1': 8, '2': 4 }
    console.log(order); // [1, 2, 4]
  });
const order = [];
const collection = { a: 1, b: 4, c: 2 };
const iterator = num => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return num * 2;
    });
};
Aigle.mapValues(collection, iterator)
  .then(object => {
    console.log(object); // { a: 2, b: 8, c: 4 }
    console.log(order); // [1, 2, 4]
  });
const collection = {
  task1: { uid: 1, name: 'test1' },
  task2: { uid: 4, name: 'test4' },
  task3: { uid: 2, name: 'test2' }
}];
Aigle.mapValues(collection, 'uid')
  .then(uids => console.log(uids)); // { task1: 1, task2: 4, task3: 2 }
Parameters:
Name Type Description
collection Array | Object
iterator function | string
Returns:

Returns an Aigle instance

Type
Aigle

mapValuesLimit(collection, limitopt, iterator) → {Aigle}

Source:

Aigle.mapValuesLimit is almost the same as Aigle.mapValues and Aigle.mapValuesSeries, but it will work with concurrency.

Examples
const order = [];
const collection = [1, 5, 3, 4, 2];
const iterator = (num, index) => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return num * 2;
    });
};
Aigle.mapValuesLimit(collection, 2, iterator)
  .then(object => {
    console.log(object); // { '0': 2, '1': 10, '2': 6, '3': 8, '4': 4 }
    console.log(order); // [1, 3, 5, 2, 4]
  });
const order = [];
const collection = { a: 1, b: 5, c: 3, d: 4, e: 2 };
const iterator = (num, key) => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return num * 2;
    });
};
Aigle.mapValuesLimit(collection, 2, iterator)
  .then(object => {
    console.log(object); // { a: 2, b: 10, c: 6, d: 8, e: 4 }
    console.log(order); // [1, 3, 5, 2, 4]
  });
const order = [];
const collection = [1, 5, 3, 4, 2];
const iterator = num => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return num * 2;
    });
};
Aigle.mapValuesLimit(collection, iterator)
  .then(object => {
    console.log(object); // { '0': 2, '1': 10, '2': 6, '3': 8, '4': 4 }
    console.log(order); // [1, 2, 3, 4, 5]
  });
Parameters:
Name Type Attributes Default Description
collection Array | Object
limit integer <optional>
8
iterator function
Returns:

Returns an Aigle instance

Type
Aigle

mapValuesSeries(collection, iterator) → {Aigle}

Source:

Aigle.mapValuesSeries is almost the same as Aigle.mapValues, but it will work in series.

Examples
const order = [];
const collection = [1, 4, 2];
const iterator = num => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return num * 2;
    });
};
Aigle.mapValuesSeries(collection, iterator)
  .then(object => {
    console.log(object); // { '0': 2, '1': 8, '2': 4 };
    console.log(order); // [1, 4, 2];
  });
const order = [];
const collection = { a: 1, b: 4, c: 2 };
const iterator = num => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return num * 2;
    });
};
Aigle.mapValuesSeries(collection, iterator)
  .then(object => {
    console.log(object); // { a: 2, b: 8, c: 4 }
    console.log(order); // [1, 4, 2];
  });
Parameters:
Name Type Description
collection Array | Object
iterator function
Returns:

Returns an Aigle instance

Type
Aigle

mixin(sources, optsopt)

Source:

Add functions which sources has to the Aigle class functions and static functions. The functions will be converted asynchronous functions. If an extended function returns a promise instance, the function will wait until the promise is resolved.

Examples
Aigle.mixin(require('lodash'));
const array = [1, 2, 3];
return Aigle.map(array, n => Aigle.delay(10, n * 2))
  .sum()
  .then(value => {
    console.log(value; // 12
  });
Aigle.mixin(require('lodash'));
const array = [1.1, 1.4, 2.2];
return Aigle.map(array, n => Aigle.delay(10, n * 2))
  .uniqBy(n => Aigle.delay(10, Math.floor(n))
  .then(array => {
    console.log(array; // [2.2, 4.4]
  });
Parameters:
Name Type Attributes Description
sources Object
opts Object <optional>
Properties
Name Type Attributes Default Description
promisify boolean <optional>
true
override boolean <optional>
false

omit(collection, iterator, …argsopt) → {Aigle}

Source:

Aigle.omit has almost the same functionality as Aigle.filter. It will return an object as a result.

Examples
const order = [];
const collection = [1, 4, 2];
const iterator = num => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return num % 2;
    });
};
Aigle.omit(collection, iterator)
  .then(object => {
    console.log(object); // { '0': 1 }
    console.log(order); // [1, 2, 4]
  });
const order = [];
const collection = { a: 1, b: 4, c: 2 };
const iterator = num => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return num * 2;
    });
};
Aigle.omit(collection, iterator)
  .then(object => {
    console.log(object); // { a: 1 }
    console.log(order); // [1, 2, 4]
  });
Parameters:
Name Type Attributes Description
collection Array | Object
iterator function | Array | Object | string
args * <optional>
<repeatable>
Returns:

Returns an Aigle instance

Type
Aigle

omitBy(collection, iterator) → {Aigle}

Source:

Aigle.omitBy has almost the same functionality as Aigle.reject. It will return an object as a result.

Examples
const order = [];
const collection = [1, 4, 2];
const iterator = num => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return num % 2;
    });
};
Aigle.omitBy(collection, iterator)
  .then(object => {
    console.log(object); // { '1': 4, '2': 4 }
    console.log(order); // [1, 2, 4]
  });
const order = [];
const collection = { a: 1, b: 4, c: 2 };
const iterator = num => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return num * 2;
    });
};
Aigle.omitBy(collection, iterator)
  .then(object => {
    console.log(object); // { b: 4, c: 2 }
    console.log(order); // [1, 2, 4]
  });
const order = [];
const collection = [{
  name: 'bargey', active: false
}, {
  name: 'fread', active: true
}];
Aigle.omitBy(collection, 'active')
  .then(object => {
    console.log(object); // { '0': { name: 'bargey', active: false } }
  });
const order = [];
const collection = [{
  name: 'bargey', active: false
}, {
  name: 'fread', active: true
}];
Aigle.omitBy(collection, ['name', 'fread'])
  .then(object => {
    console.log(object); // { '0': { name: 'bargey', active: false } }
  });
const order = [];
const collection = [{
  name: 'bargey', active: false
}, {
  name: 'fread', active: true
}];
Aigle.omitBy(collection, { name: 'fread', active: true })
  .then(object => {
    console.log(object); // { '0': { name: 'bargey', active: false } }
  });
Parameters:
Name Type Description
collection Array | Object
iterator function | Array | Object | string
Returns:

Returns an Aigle instance

Type
Aigle

omitByLimit(limitopt, iterator)

Source:
Parameters:
Name Type Attributes Default Description
limit number <optional>
8
iterator function

omitByLimit(collection, limitopt, iterator) → {Aigle}

Source:

Aigle.omitByLimit is almost the as Aigle.omitBy and Aigle.omitBySeries, but it will work with concurrency.

Examples
const order = [];
const collection = [1, 5, 3, 4, 2];
const iterator = (num, index) => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return num % 2;
    });
};
Aigle.omitByLimit(collection, 2, iterator)
  .then(object => {
    console.log(object); // { '3': 4, '4': 2 }
    console.log(order); // [1, 3, 5, 2, 4]
  });
const order = [];
const collection = { a: 1, b: 5, c: 3, d: 4, e: 2 };
const iterator = (num, key) => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return num % 2;
    });
};
Aigle.omitByLimit(collection, 2, iterator)
  .then(object => {
    console.log(object); // { d: 4, e: 2 }
    console.log(order); // [1, 3, 5, 2, 4]
  });
const order = [];
const collection = [1, 5, 3, 4, 2];
const iterator = num => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return num % 2;
    });
};
Aigle.omitByLimit(collection, iterator)
  .then(object => {
    console.log(object); // { '3': 4, '4': 2 }
    console.log(order); // [1, 2, 3, 4, 5]
  });
Parameters:
Name Type Attributes Default Description
collection Array | Object
limit integer <optional>
8
iterator function
Returns:

Returns an Aigle instance

Type
Aigle

omitBySeries(iterator)

Source:
Parameters:
Name Type Description
iterator function

omitBySeries(collection, iterator) → {Aigle}

Source:

Aigle.omitBySeries is almost the as Aigle.omitBy, but it will work in series.

Examples
const order = [];
const collection = [1, 4, 2];
const iterator = num => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return num % 2;
    });
};
Aigle.omitBySeriesSeries(collection, iterator)
  .then(object => {
    console.log(object); // { '1': 4, '2': 2 }
    console.log(order); // [1, 4, 2]
  });
const order = [];
const collection = { a: 1, b: 4, c: 2 };
const iterator = num => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return num % 2;
    });
};
Aigle.omitBySeriesSeries(collection, iterator)
  .then(object => {
    console.log(object); // { b: 4, c: 2 }
    console.log(order); // [1, 4, 2]
  });
Parameters:
Name Type Description
collection Array | Object
iterator function
Returns:

Returns an Aigle instance

Type
Aigle

parallel(collection)

Source:

Aigle.parallel functionality is similar to Aigle.all and Aigle.props, and the function allows function collection.

Examples
Aigle.parallel([
    () => Aigle.delay(30, 1),
    Aigle.delay(20, 2),
    3
  ]).then(array => {
    console.log(array); // [1, 2, 3]
  });
Aigle.parallel({
    a: () => Aigle.delay(30, 1),
    b: Aigle.delay(20, 2),
    c: 3
  }).then(obj => {
    console.log(obj); // { a: 1, b: 2, c: 3 }
  });
Parameters:
Name Type Description
collection Array | Object

it should be an array/object of functions or Promise instances

parallelLimit(collection, limitopt)

Source:

Aigle.parallel functionality has the same functionality as Aigle.parallel and it works with concurrency.

Examples
Aigle.parallelLimit([
    () => Aigle.delay(30, 1),
    Aigle.delay(20, 2),
    3
  ]).then(array => {
    console.log(array); // [1, 2, 3]
  });
Aigle.parallelLimit({
    a: () => Aigle.delay(30, 1),
    b: Aigle.delay(20, 2),
    c: 3
  }, 2).then(obj => {
    console.log(obj); // { a: 1, b: 2, c: 3 }
  });
Parameters:
Name Type Attributes Default Description
collection Array | Object

it should be an array/object of functions or Promise instances

limit integer <optional>
8

It is concurrncy, default is 8

pick(collection, iterator, …argsopt) → {Aigle}

Source:

Aigle.pick has almost the same functionality as Aigle.filter. It will return an object as a result.

Examples
const order = [];
const collection = [1, 4, 2];
const iterator = num => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return num % 2;
    });
};
Aigle.pick(collection, iterator)
  .then(object => {
    console.log(object); // { '0': 1 }
    console.log(order); // [1, 2, 4]
  });
const order = [];
const collection = { a: 1, b: 4, c: 2 };
const iterator = num => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return num * 2;
    });
};
Aigle.pick(collection, iterator)
  .then(object => {
    console.log(object); // { a: 1 }
    console.log(order); // [1, 2, 4]
  });
Parameters:
Name Type Attributes Description
collection Array | Object
iterator function | Array | Object | string
args * <optional>
<repeatable>
Returns:

Returns an Aigle instance

Type
Aigle

pickBy(collection, iterator) → {Aigle}

Source:

Aigle.pickBy has almost the same functionality as Aigle.filter. It will return an object as a result.

Examples
const order = [];
const collection = [1, 4, 2];
const iterator = num => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return num % 2;
    });
};
Aigle.pickBy(collection, iterator)
  .then(object => {
    console.log(object); // { '0': 1 }
    console.log(order); // [1, 2, 4]
  });
const order = [];
const collection = { a: 1, b: 4, c: 2 };
const iterator = num => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return num * 2;
    });
};
Aigle.pickBy(collection, iterator)
  .then(object => {
    console.log(object); // { a: 1 }
    console.log(order); // [1, 2, 4]
  });
const order = [];
const collection = [{
  name: 'bargey', active: false
}, {
  name: 'fread', active: true
}];
Aigle.pickBy(collection, 'active')
  .then(object => {
    console.log(object); // { '1': { name: 'fread', active: true } }
  });
const order = [];
const collection = [{
  name: 'bargey', active: false
}, {
  name: 'fread', active: true
}];
Aigle.pickBy(collection, ['name', 'fread'])
  .then(object => {
    console.log(object); // { '1': { name: 'fread', active: true } }
  });
const order = [];
const collection = [{
  name: 'bargey', active: false
}, {
  name: 'fread', active: true
}];
Aigle.pickBy(collection, { name: 'fread', active: true })
  .then(object => {
    console.log(object); // { '1': { name: 'fread', active: true } }
  });
Parameters:
Name Type Description
collection Array | Object
iterator function | Array | Object | string
Returns:

Returns an Aigle instance

Type
Aigle

pickByLimit(limitopt, iterator)

Source:
Parameters:
Name Type Attributes Default Description
limit number <optional>
8
iterator function

pickByLimit(collection, limitopt, iterator) → {Aigle}

Source:

Aigle.pickByLimit is almost the as Aigle.pickBy and Aigle.pickBySeries, but it will work with concurrency.

Examples
const order = [];
const collection = [1, 5, 3, 4, 2];
const iterator = (num, index) => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return num % 2;
    });
};
Aigle.pickByLimit(collection, 2, iterator)
  .then(object => {
    console.log(object); // { '0': 1, '1': 5, '2': 3 }
    console.log(order); // [1, 3, 5, 2, 4]
  });
const order = [];
const collection = { a: 1, b: 5, c: 3, d: 4, e: 2 };
const iterator = (num, key) => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return num % 2;
    });
};
Aigle.pickByLimit(collection, 2, iterator)
  .then(object => {
    console.log(object); // { a: 1, b: 5, c: 3 }
    console.log(order); // [1, 3, 5, 2, 4]
  });
const order = [];
const collection = [1, 5, 3, 4, 2];
const iterator = num => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return num % 2;
    });
};
Aigle.pickByLimit(collection, iterator)
  .then(object => {
    console.log(object); // { '0': 1, '1': 5, '2': 3 }
    console.log(order); // [1, 2, 3, 4, 5]
  });
Parameters:
Name Type Attributes Default Description
collection Array | Object
limit integer <optional>
8
iterator function
Returns:

Returns an Aigle instance

Type
Aigle

pickBySeries(iterator)

Source:
Parameters:
Name Type Description
iterator function

pickBySeries(collection, iterator) → {Aigle}

Source:

Aigle.pickBySeries is almost the as Aigle.pickBy, but it will work in series.

Examples
const order = [];
const collection = [1, 4, 2];
const iterator = num => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return num % 2;
    });
};
Aigle.pickBySeries(collection, iterator)
  .then(object => {
    console.log(object); // { '0': 1 }
    console.log(order); // [1, 4, 2]
  });
const order = [];
const collection = { a: 1, b: 4, c: 2 };
const iterator = num => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return num * 2;
    });
};
Aigle.pickBySeries(collection, iterator)
  .then(object => {
    console.log(object); // { a: 1 }
    console.log(order); // [1, 4, 2]
  });
Parameters:
Name Type Description
collection Array | Object
iterator function
Returns:

Returns an Aigle instance

Type
Aigle

promisify(fn, fnopt)

Source:
Examples
const func = (a, b, c, callback) => callback(null, a + b + c);
Aigle.promisify(func)(1, 2, 3)
  .then(value => console.log(value)); // 6
const obj = {
  val: 1,
  get(callback) {
    callback(null, this.val);
  }
};

// using bind
Aigle.promisify(obj.get.bind(obj))().then(console.log);

// using context
Aigle.promisify(obj.get, { context: obj })().then(console.log);

// using shorthand
Aigle.promisify(obj, 'get')().then(console.log);
Parameters:
Name Type Attributes Description
fn Object | function
fn string | number | Object <optional>
Properties
Name Type Attributes Description
context Object <optional>

promisifyAll(target, optsopt)

Source:
Example
const redis = require('redis');
Aigle.promisifyAll(redis);
const client = redis.createClient();

const key = 'test';
redis.hsetAsync(key, 1)
  .then(() => redis.hgetAsync(key))
  .then(value => console.log(value)); // 1
Parameters:
Name Type Attributes Description
target Object
opts Object <optional>
Properties
Name Type Attributes Default Description
suffix String <optional>
Async
filter function <optional>
depth Integer <optional>
2

props(object)

Source:

Aigle.props is almost the same functionality as Aigle.all But the function allows an object as the first argument instead of an array.

Example
const order = [];
const makeDelay = (num, delay) => {
  return Aigle.delay(delay)
    .then(() => {
      order.push(num);
      return num;
    });
};
Aigle.props({
  a: makeDelay(1, 30),
  b: makeDelay(2, 20),
  c: makeDelay(3, 10)
})
.then(object => {
  console.log(object); // { a: 1, b: 2, c: 3 }
  console.log(order); // [3, 2, 1]
});
Parameters:
Name Type Description
object Object

race(collection)

Source:
Examples
Aigle.race([
  new Aigle(resolve => setTimeout(() => resolve(1), 30)),
  new Aigle(resolve => setTimeout(() => resolve(2), 20)),
  new Aigle(resolve => setTimeout(() => resolve(3), 10))
])
.then(value => console.log(value)); // 3
Aigle.race({
  a: new Aigle(resolve => setTimeout(() => resolve(1), 30)),
  b: new Aigle(resolve => setTimeout(() => resolve(2), 20)),
  c: new Aigle(resolve => setTimeout(() => resolve(3), 10))
})
.then(value => console.log(value)); // 3
Parameters:
Name Type Description
collection Object | Array

reduce(collection, iterator, resultopt) → {Aigle}

Source:
Examples
const collection = [1, 4, 2];
const iterator = (result, num, index) => {
  return Aigle.delay(num * 10)
    .then(() => result + num);
};
return Aigle.reduce(collection, iterator, 1)
  .then(value => console.log(value)); // 8
const collection = { a: 1, b: 4, c: 2 };
const iterator = (result, num, key) => {
  return Aigle.delay(num * 10)
    .then(() => result + num);
};
return Aigle.reduce(collection, iterator, '')
  .then(value => console.log(value)); // '142'
Parameters:
Name Type Attributes Description
collection Array | Object
iterator function
result * <optional>
Returns:

Returns an Aigle instance

Type
Aigle

reject(collection, iteratoropt) → {Aigle}

Source:

Aigle reject has two features. One of them is basic Promise.reject function, it returns a rejected Aigle instance. The other is a collection function, it requires an iterator function. It is the opposite of filter. If the iterator function is not defined, the function works as a first one.

Examples
const error = new Error('error');
Aigle.reject(error)
  .catch(error => {
    console.log(error); // error
  });
const order = [];
const collection = [1, 4, 2];
const iterator = (num, index) => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return num % 2;
    });
};
Aigle.reject(collection, iterator)
  .then(array => {
    console.log(array); // [4, 2];
    console.log(order); // [1, 2, 4];
  });
const order = [];
const collection = { a: 1, b: 4, c: 2 };
const iterator = (num, key) => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return num % 2;
    });
};
Aigle.reject(collection, iterator)
  .then(array => {
    console.log(array); // [4, 2];
    console.log(order); // [1, 2, 4];
  });
const order = [];
const collection = [{
  name: 'bargey', active: false
}, {
  name: 'fread', active: true
}];
Aigle.reject(collection, 'active')
  .then(array => {
    console.log(array); // [{ name: 'fread', active: false }]
  });
const order = [];
const collection = [{
  name: 'bargey', active: false
}, {
  name: 'fread', active: true
}];
Aigle.reject(collection, ['name', 'bargey'])
  .then(array => {
    console.log(array); // [{ name: 'fread', active: false }]
  });
const order = [];
const collection = [{
  name: 'bargey', active: false
}, {
  name: 'fread', active: true
}];
Aigle.reject(collection, { name: 'bargey', active: false })
  .then(array => {
    console.log(array); // [{ name: 'fread', active: false }]
  });
Parameters:
Name Type Attributes Description
collection function | Array | Object
iterator function | Array | Object | string <optional>
Returns:

Returns an Aigle instance

Type
Aigle

rejectLimit(collection, limitopt, iterator) → {Aigle}

Source:
Examples
const order = [];
const collection = [1, 5, 3, 4, 2];
const iterator = (num, index) => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return num % 2;
    });
};
Aigle.rejectLimit(collection, 2, iterator)
  .then(array => {
    console.log(array); // [4, 2]
    console.log(order); // [1, 3, 5, 2, 4]
  });
const order = [];
const collection = { a: 1, b: 5, c: 3, d: 4, e: 2 };
const iterator = (num, key) => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return num % 2;
    });
};
Aigle.rejectLimit(collection, 2, iterator)
  .then(array => {
    console.log(array); // [4, 2]
    console.log(order); // [1, 3, 5, 2, 4]
  });
const order = [];
const collection = [1, 5, 3, 4, 2];
const iterator = num => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return num % 2;
    });
};
Aigle.rejectLimit(collection, iterator)
  .then(array => {
    console.log(array); // [4, 2]
    console.log(order); // [1, 2, 3, 4, 5]
  });
Parameters:
Name Type Attributes Default Description
collection Array | Object
limit integer <optional>
8
iterator function
Returns:

Returns an Aigle instance

Type
Aigle

rejectSeries(collection, iterator) → {Aigle}

Source:
Examples
const order = [];
const collection = [1, 4, 2];
const iterator = (num, index) => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return num % 2;
    });
};
Aigle.rejectSeries(collection, iterator)
  .then(array => {
    console.log(array); // [4, 2];
    console.log(order); // [1, 4, 2];
  });
const order = [];
const collection = { a: 1, b: 4, c: 2 };
const iterator = (num, key) => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return num % 2;
    });
};
Aigle.rejectSeries(collection, iterator)
  .then(array => {
    console.log(array); // [4, 2];
    console.log(order); // [1, 4, 2];
  });
Parameters:
Name Type Description
collection Array | Object
iterator function
Returns:

Returns an Aigle instance

Type
Aigle

retry(timesopt, handler)

Source:
Examples
let called = 0;
Aigle.retry(3, () => {
  return new Aigle((resolve, reject) => {
    setTimeout(() => reject(++called), 10);
  });
})
.catch(error => {
  console.log(error); // 3
  console.log(called); // 3
});
let called = 0;
Aigle.retry(() => {
  return new Aigle((resolve, reject) => {
    setTimeout(() => reject(++called), 10);
  });
})
.catch(error => {
  console.log(error); // 5
  console.log(called); // 5
});
let called = 0;
const opts = {
  times: 5,
  interval: 10
};
Aigle.retry(opts, () => {
  return new Aigle((resolve, reject) => {
    setTimeout(() => reject(++called), 10);
  });
})
.catch(error => {
  console.log(error); // 5
  console.log(called); // 5
});
let called = 0;
const opts = {
  times: 5,
  interval: c => c * 2;
};
Aigle.retry(opts, () => {
  return new Aigle((resolve, reject) => {
    setTimeout(() => reject(++called), 10);
  });
})
.catch(error => {
  console.log(error); // 5
  console.log(called); // 5
});
Parameters:
Name Type Attributes Default Description
times Integer | Object <optional>
5
handler function

series(collection)

Source:

Aigle.series functionality has the same functionality as Aigle.parallel and it works in series.

Examples
Aigle.series([
    () => Aigle.delay(30, 1),
    Aigle.delay(20, 2),
    3
  ]).then(array => {
    console.log(array); // [1, 2, 3]
  });
Aigle.series({
    a: () => Aigle.delay(30, 1),
    b: Aigle.delay(20, 2),
    c: 3
  }).then(obj => {
    console.log(obj); // { a: 1, b: 2, c: 3 }
  });
Parameters:
Name Type Description
collection Array | Object

it should be an array/object of functions or Promise instances

some(collection, iterator) → {Aigle}

Source:

Aigle.some has almost the same functionality as Array#some. It iterates all elements of collection and executes iterator using each element on parallel. The iterator needs to return a promise or something.. If a promise is returned, the function will wait until the promise is fulfilled. If the result is truthy, the function will return true otherwise false.

Examples
const order = [];
const collection = [1, 4, 2];
const iterator = num => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return num % 2 === 0;
    });
};
Aigle.some(collection, iterator)
  .then(bool => {
    console.log(bool); // true
    console.log(order); // [1, 2]
  });
const order = [];
const collection = { a: 1, b: 4, c: 2 };
const iterator = num => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return num % 2 === 0;
    });
};
Aigle.some(collection, iterator)
  .then(bool => {
    console.log(bool); // true
    console.log(order); // [1, 2]
  });
const order = [];
const collection = [1, 4, 2];
const iterator = num => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return false;
    });
};
Aigle.some(collection, iterator)
  .then(bool => {
    console.log(bool); // false
    console.log(order); // [1, 2, 4]
  });
const collection = [{
 uid: 1, active: false
}, {
 uid: 4, active: true
}, {
 uid: 2, active: true
}];
Aigle.some(collection, 'active')
  .then(value => console.log(value)); // true
const collection = [{
 uid: 1, active: false
}, {
 uid: 4, active: true
}, {
 uid: 2, active: true
}];
Aigle.some(collection, ['uid', 4])
  .then(value => console.log(value)); // true
const collection = [{
 uid: 1, active: false
}, {
 uid: 4, active: true
}, {
 uid: 2, active: true
}];
Aigle.some(collection, { uid: 4 })
  .then(value => console.log(value)); // true
Parameters:
Name Type Description
collection Array | Object
iterator function | Array | Object | string
Returns:

Returns an Aigle instance

Type
Aigle

someLimit(collection, limitopt, iterator) → {Aigle}

Source:

Aigle.someLimit is almost the as Aigle.some and Aigle.someSeries, but it will work with concurrency.

Examples
const order = [];
const collection = [1, 5, 3, 4, 2];
const iterator = (num, index) => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return num % 2 === 0;
    });
};
Aigle.someLimit(collection, 2, iterator)
  .then(bool => {
    console.log(bool); // true
    console.log(order); // [1, 3, 5, 2]
  });
const order = [];
const collection = { a: 1, b: 5, c: 3, d: 4, e: 2 };
const iterator = (num, key) => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return num % 2 === 0;
    });
};
Aigle.someLimit(collection, 2, iterator)
  .then(bool => {
    console.log(bool); // true
    console.log(order); // [1, 3, 5, 2]
  });
const order = [];
const collection = [1, 5, 3, 4, 2];
const iterator = num => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return num % 2 === 0;
    });
};
Aigle.someLimit(collection, iterator)
  .then(bool => {
    console.log(bool); // true
    console.log(order); // [1, 2]
  });
Parameters:
Name Type Attributes Default Description
collection Array | Object
limit integer <optional>
8
iterator function
Returns:

Returns an Aigle instance

Type
Aigle

someSeries(collection, iterator) → {Aigle}

Source:

Aigle.someSeries is almost the as Aigle.some, but it will work in series.

Examples
const order = [];
const collection = [1, 4, 2];
const iterator = num => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return num % 2 === 0;
    });
};
Aigle.someSeries(collection, iterator)
  .then(bool => {
    console.log(bool); // true
    console.log(order); // [1, 4]
  });
const order = [];
const collection = { a: 1, b: 4, c: 2 };
const iterator = num => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return num % 2 === 0;
    });
};
Aigle.someSeries(collection, iterator)
  .then(bool => {
    console.log(bool); // true
    console.log(order); // [1, 4]
  });
const order = [];
const collection = [1, 4, 2];
const iterator = num => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return false;
    });
};
Aigle.someSeries(collection, iterator)
  .then(bool => {
    console.log(bool); // false
    console.log(order); // [1, 4, 2]
  });
Parameters:
Name Type Description
collection Array | Object
iterator function
Returns:

Returns an Aigle instance

Type
Aigle

sortBy(collection, iterator) → {Aigle}

Source:

It iterates all elements of collection and executes iterator using each element on parallel. It creates a sorted array which is ordered by results of iterator.

Examples
const order = [];
const collection = [1, 4, 2];
const iterator = num => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return num;
    });
};
Aigle.sortBy(collection, iterator)
  .then(array => {
    console.log(array); // [1, 2, 4]
    console.log(order); // [1, 2, 4]
  });
const order = [];
const collection = { a: 1, b: 4, c: 2 };
const iterator = num => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return num;
    });
};
Aigle.sortBy(collection, iterator)
  .then(array => {
    console.log(array); // [1, 2, 4]
    console.log(order); // [1, 2, 4]
  });
const order = [];
const collection = [{
  uid: 2, name: 'bargey', uid: 2
}, {
  uid: 1, name: 'fread'
}];
Aigle.sortBy(collection, 'uid')
  .then(array => {
    console.log(array); // [{ uid: 1, name: 'fread' }, { uid: 2, name: 'bargey' ]
  });
Parameters:
Name Type Description
collection Array | Object
iterator function | string
Returns:

Returns an Aigle instance

Type
Aigle

sortByLimit(collection, limitopt, iterator) → {Aigle}

Source:

Aigle.sortByLimit is almost the smae as Aigle.sortBy and Aigle.sortBySeries, but it will work with concurrency.

Examples
const order = [];
const collection = [1, 5, 3, 4, 2];
const iterator = (num, index) => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return num;
    });
};
Aigle.sortByLimit(collection, 2, iterator)
  .then(array => {
    console.log(array); // [1, 2, 3, 4, 5]
    console.log(order); // [1, 3, 5, 2, 4]
  });
const order = [];
const collection = { a: 1, b: 5, c: 3, d: 4, e: 2 };
const iterator = (num, key) => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return num;
    });
};
Aigle.sortByLimit(collection, 2, iterator)
  .then(array => {
    console.log(array); // [1, 2, 3, 4, 5]
    console.log(order); // [1, 3, 5, 2, 4]
  });
const order = [];
const collection = [1, 5, 3, 4, 2];
const iterator = num => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return num;
    });
};
Aigle.sortByLimit(collection, iterator)
  .then(array => {
    console.log(array); // [1, 2, 3, 4, 5]
    console.log(order); // [1, 2, 3, 4, 5]
  });
Parameters:
Name Type Attributes Default Description
collection Array | Object
limit integer <optional>
8
iterator function
Returns:

Returns an Aigle instance

Type
Aigle

sortBySeries(collection, iterator) → {Aigle}

Source:

Aigle.sortBySeries is almost the smae as Aigle.sortBy, but it will work in series.

Examples
const order = [];
const collection = [1, 4, 2];
const iterator = num => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return num;
    });
};
Aigle.sortBySeries(collection, iterator)
  .then(array => {
    console.log(array); // [1, 2, 4]
    console.log(order); // [1, 4, 2]
  });
const order = [];
const collection = { a: 1, b: 4, c: 2 };
const iterator = num => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      return num;
    });
};
Aigle.sortBySeries(collection, iterator)
  .then(array => {
    console.log(array); // [1, 2, 4]
    console.log(order); // [1, 4, 2]
  });
Parameters:
Name Type Description
collection Array | Object
iterator function
Returns:

Returns an Aigle instance

Type
Aigle

times(times, iterator) → {Aigle}

Source:
Example
const order = [];
const timer = [30, 20, 10];
const iterator = n => {
  return Aigle.delay(timer[n])
    .then(() => {
      order.push(n);
      return n;
    });
};
Aigle.times(3, iterator)
  .then(array => {
    console.log(array); // [0, 1, 2]
    console.log(order); // [2, 1, 0]
  });
Parameters:
Name Type Description
times integer
iterator function
Returns:

Returns an Aigle instance

Type
Aigle

timesLimit(times, limitopt, iterator) → {Aigle}

Source:
Examples
const order = [];
const timer = [30, 20, 10];
const iterator = n => {
  return Aigle.delay(timer[n])
    .then(() => {
      order.push(n);
      return n;
    });
};
Aigle.timesLimit(3, 2, iterator)
  .then(array => {
    console.log(array); // [0, 1, 2]
    console.log(order); // [1, 0, 2]
  });
const order = [];
const timer = [30, 20, 10];
const iterator = n => {
  return Aigle.delay(timer[n])
    .then(() => {
      order.push(n);
      return n;
    });
};
Aigle.timesLimit(3, iterator)
  .then(array => {
    console.log(array); // [0, 1, 2]
    console.log(order); // [2, 1, 0]
  });
Parameters:
Name Type Attributes Default Description
times integer
limit integer <optional>
8
iterator function
Returns:

Returns an Aigle instance

Type
Aigle

timesSeries(times, iterator) → {Aigle}

Source:
Example
const order = [];
const timer = [30, 20, 10];
const iterator = n => {
  return Aigle.delay(timer[n])
    .then(() => {
      order.push(n);
      return n;
    });
};
Aigle.timesSeries(3, iterator)
  .then(array => {
    console.log(array); // [0, 1, 2]
    console.log(order); // [0, 1, 2]
  });
Parameters:
Name Type Description
times integer
iterator function
Returns:

Returns an Aigle instance

Type
Aigle

transform(collection, iterator, accumulatoropt) → {Aigle}

Source:
Examples
const order = [];
const collection = [1, 4, 2];
const iterator = (result, num, index) => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      result[index] = num;
    });
};
Aigle.transform(collection, iterator, {})
  .then(object => {
    console.log(object); // { '0': 1, '1': 4, '2': 2 }
    console.log(order); // [1, 2, 4]
  });
const order = [];
const collection = [1, 4, 2];
const iterator = (result, num, index) => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      result.push(num);
    });
};
Aigle.transform(collection, iterator, {})
  .then(array => {
    console.log(array); // [1, 2, 4]
    console.log(order); // [1, 2, 4]
  });
const order = [];
const collection = { a: 1, b: 4, c: 2 };
const iterator = (result, num, key) => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      result.push(num);
      return num !== 2;
    });
};
Aigle.transform(collection, iterator, [])
  .then(array => {
    console.log(array); // [1, 2]
    console.log(order); // [1, 2]
  });
Parameters:
Name Type Attributes Description
collection Array | Object
iterator function
accumulator Array | Object <optional>
Returns:

Returns an Aigle instance

Type
Aigle

transformLimit(collection, limitopt, iterator, accumulatoropt)

Source:
Examples
const order = [];
const collection = [1, 5, 3, 4, 2];
const iterator = (result, num, index) => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      result[index] = num;
    });
};
Aigle.transformLimit(collection, 2, iterator, {})
  .then(object => {
    console.log(object); // { '0': 1, '1': 5, '2': 3, '3': 4, '4': 2 }
    console.log(order); // [1, 5, 3, 4, 2]
  });
const order = [];
const collection = [1, 5, 3, 4, 2];
const iterator = (result, num, index) => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      result.push(num);
    });
};
Aigle.transformLimit(collection, 2, iterator, {})
  .then(array => {
    console.log(array); // [1, 5, 3, 4, 2]
    console.log(order); // [1, 5, 3, 4, 2]
  });
const order = [];
const collection = { a: 1, b: 5, c: 3, d: 4, e: 2 };
const iterator = (result, num, key) => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      result.push(num);
      return num !== 4;
    });
};
Aigle.transformLimit(collection, 2, iterator, [])
  .then(array => {
    console.log(array); // [1, 5, 3, 4]
    console.log(order); // [1, 5, 3, 4]
  });
const order = [];
const collection = { a: 1, b: 5, c: 3, d: 4, e: 2 };
const iterator = (result, num, key) => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      result.push(num);
      return num !== 4;
    });
};
Aigle.transformLimit(collection, iterator, [])
  .then(array => {
    console.log(array); // [1, 2, 3, 4]
    console.log(order); // [1, 2, 3, 4]
  });
Parameters:
Name Type Attributes Description
collection Array | Object
limit integer <optional>
iterator function
accumulator Array | Object <optional>

transformSeries(collection, iterator, accumulatoropt) → {Aigle}

Source:
Examples
const order = [];
const collection = [1, 4, 2];
const iterator = (result, num, index) => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      result[index] = num;
    });
};
Aigle.transformSeries(collection, iterator, {})
  .then(object => {
    console.log(object); // { '0': 1, '1': 4, '2': 2 }
    console.log(order); // [1, 4, 2]
  });
const order = [];
const collection = [1, 4, 2];
const iterator = (result, num, index) => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      result.push(num);
    });
};
Aigle.transformSeries(collection, iterator, {})
  .then(array => {
    console.log(array); // [1, 4, 2]
    console.log(order); // [1, 4, 2]
  });
const order = [];
const collection = { a: 1, b: 4, c: 2 };
const iterator = (result, num, key) => {
  return Aigle.delay(num * 10)
    .then(() => {
      order.push(num);
      result.push(num);
      return num !== 4;
    });
};
Aigle.transformSeries(collection, iterator, [])
  .then(array => {
    console.log(array); // [1, 4]
    console.log(order); // [1, 4]
  });
Parameters:
Name Type Attributes Description
collection Array | Object
iterator function
accumulator Array | Object <optional>
Returns:

Returns an Aigle instance

Type
Aigle

until(valueopt, tester, iterator)

Source:
Parameters:
Name Type Attributes Description
value * <optional>
tester function
iterator function

whilst(valueopt, tester, iterator)

Source:
Parameters:
Name Type Attributes Description
value * <optional>
tester function
iterator function