composeAsync

Medium20 minAdobe

Prompt

Implement a composeAsync function that takes any number of functions (sync or async) and returns a new function. When the returned function is called with a value, it applies the given functions right to left, awaiting each step before passing the result to the next.

If no functions are passed, the returned function should resolve with its input unchanged.

Requirements

  • Takes any number of functions and returns a new function
  • The returned function takes one value and returns a promise
  • Functions run from right to left; each one receives the resolved value of the function to its right
  • Works for a mix of sync and async functions
  • With no functions, the returned function resolves with its input unchanged
  • If any function throws or its returned promise rejects, the composed promise rejects