batch-promises icon indicating copy to clipboard operation
batch-promises copied to clipboard

Changing arguments order

Open nfroidure opened this issue 8 years ago • 3 comments

Would be nice to change the arguments order in order to put the collection at the end. This would allow the following usage:

import batchPromises from 'batch-promises';

Promise.resolve([1, 2, 3, 4, 5])
.then(batchPromises.bind(null, function() { }, 4));

Note i also put the Iteratee as the first argument since we also could want to set the batch size dynamically:

import batchPromises from 'batch-promises';

Promise.all([
  4,
  [1, 2, 3, 4, 5]
])
.spread(batchPromises.bind(null, function() { }));

It could be an occasion to publish a 1.0.0 version and embrace semver at the same time ;).

Let me know if you want me to do a PR according to those changes.

nfroidure avatar Mar 30 '16 11:03 nfroidure

This + the option to return a function that takes a collection if none is passed through could lead to a nice api, eg:

import batchPromises from 'batch-promises';

Promise.resolve([1, 2, 3, 4, 5])
.then(batchPromises(somethingAsync, 3))
.then(batchPromises(somethingElseAsync, 3));

thoughts?

Nicktho avatar Apr 05 '16 01:04 Nicktho

Also, down to embrace semver :D

Nicktho avatar Apr 05 '16 01:04 Nicktho

Not sure if it worth currying by default since most people would rather use their own library for it. Some libraries like R also allow to flip arguments etc. It is also very simple to achieve currying in ES6 http://macr.ae/article/es6-and-currying.html

nfroidure avatar Apr 05 '16 07:04 nfroidure