FxTS
FxTS copied to clipboard
function: `spreadArgs` (maybe not the best name)
Suggestion
Yeah, I don't think the name is good too 🤣. If you want to add this function to the library, please suggest a better name.
⭐ Suggestion
const fn = (a: A, b: B, ...) => ...
spreadArgs(fn)([a as A, b as B, ...])
Implement
const spreadArgs = <F extends Arrow>(fn: F):
(args: Parameters<typeof fn> | readonly [...Parameters<typeof fn>]) =>
ReturnType<typeof fn> =>
(args) => fn(...args);
💻 Use Cases
It's useful with map:
import { writeFile } from "node:fs/promises";
const contentByPath = {
"a.txt": "Hello, world",
"b.json", "{ \"hello\": \"world\" }"
}
await pipe(
contentByPath,
entries,
map(spreadArgs(writeFile)),
toAsync,
)