2023-02-06 15:59:47 +01:00

35 lines
548 B
JavaScript

'use strict';
const pMap = require('p-map');
const { curry } = require('lodash/fp');
function pipeAsync(...methods) {
return async (data) => {
let res = data;
for (const method of methods) {
res = await method(res);
}
return res;
};
}
/**
* @type { import('./async').MapAsync }
*/
const mapAsync = curry(pMap);
/**
* @type { import('./async').ForEachAsync }
*/
const forEachAsync = curry(async (array, func) => {
await mapAsync(array, func);
});
module.exports = {
mapAsync,
forEachAsync,
pipeAsync,
};