2022-12-08 17:17:11 +01:00
|
|
|
'use strict';
|
|
|
|
|
2023-01-17 15:07:27 +01:00
|
|
|
const pMap = require('p-map');
|
|
|
|
const { curry } = require('lodash/fp');
|
2022-12-20 12:00:49 +01:00
|
|
|
|
2022-12-08 17:17:11 +01:00
|
|
|
function pipeAsync(...methods) {
|
|
|
|
return async (data) => {
|
|
|
|
let res = data;
|
|
|
|
|
|
|
|
for (const method of methods) {
|
|
|
|
res = await method(res);
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2023-01-17 15:07:27 +01:00
|
|
|
* @type { import('./async').MapAsync }
|
2022-12-08 17:17:11 +01:00
|
|
|
*/
|
2023-01-17 15:07:27 +01:00
|
|
|
const mapAsync = curry(pMap);
|
2022-12-08 17:17:11 +01:00
|
|
|
|
2023-02-06 15:59:47 +01:00
|
|
|
/**
|
|
|
|
* @type { import('./async').ForEachAsync }
|
|
|
|
*/
|
2023-02-06 19:11:58 +01:00
|
|
|
const forEachAsync = curry(async (array, func, options) => {
|
|
|
|
await mapAsync(array, func, options);
|
2023-02-06 15:59:47 +01:00
|
|
|
});
|
|
|
|
|
2022-12-08 17:17:11 +01:00
|
|
|
module.exports = {
|
|
|
|
mapAsync,
|
2023-02-06 15:59:47 +01:00
|
|
|
forEachAsync,
|
2022-12-08 17:17:11 +01:00
|
|
|
pipeAsync,
|
|
|
|
};
|