metarhia / metasync

Asynchronous Programming Library for JavaScript & Node.js
https://metarhia.com
MIT License
206 stars 35 forks source link

Make metasync.map compatible with Array.map #325

Open tshemsedinov opened 6 years ago

tshemsedinov commented 6 years ago

Compare

Array.prototype.map((value, index, array) => (result) [, thisArg]) : Array

and current implementation:

metasync.map(array, (value, callback) => callback(result) [, thisArg]);

we may change to:

metasync.map(array, (value, [index], [array], callback) => callback(result));
o-rumiantsev commented 6 years ago

@tshemsedinov current implementation of metasync.map has such contract:

metasync.map(array, (value, callback) => callback(err, result), done);

As I understand we should change it to:

metasync.map(array,  (value, [index[, array]], callback) => callback(err, result), done);

Or we may also add optional thisArg to contract, so this will look like this:

metasync.map(array,  (value, [index[, array]], callback) => callback(err, result) [, thisArg],  done);
nechaido commented 6 years ago

@tshemsedinov I'd prefer to leave it as it is, but we should use Iterators instead of Arrays, so that any Iterable object may be passed to metasync.map and other functions (#313). On the other hand, we can create metasync.Iterator for such use-cases. WDYT?