@ledgerhq/live-common
Version:
Common ground for the Ledger Live apps
25 lines • 1.01 kB
JavaScript
;
/**
*
* @param hooks - An array of functions that take an array of items of type T and return an array of items of type U or undefined.
* @template T - The type of the items in the input array.
* @template U - The type of the items in the output array.
* @description This function composes multiple hooks into a single hook that processes an array of items of type T and returns an array of items of type T & U.
* @returns A function that takes an array of items of type T and returns an array of items of type T & U.
*
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.composeHooks = void 0;
function composeHooks(...hooks) {
return (items) => {
return hooks.reduce((acc, hook) => {
const result = hook?.(acc) ?? [];
return acc.map((item, i) => ({
...item,
...result[i],
}));
}, items);
};
}
exports.composeHooks = composeHooks;
//# sourceMappingURL=composeHooks.js.map