Skip to content

function: spreadArgs (maybe not the best name) #347

Open

Description

@2chanhaeng

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,
)

Activity

  1. ppeeou commented on Sep 14, 2025

    @ppeeou
    Member

    https://fxts.dev/docs/apply

    Thank you for your interest. A function with the same functionality already exists :)

  2. 2chanhaeng commented on Sep 14, 2025

    @2chanhaeng
    ContributorAuthor

    Oh, I missed that!
    And then, would you consider to fix T extends Parameters<F> | readonly [...Parameters<typeof fn>] at the apply function?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions