Async
aCompose

Performs functions composition from right to left asynchronously.

💡

The compose function is equivalent to a(b(c(val))).

Related

Syntax

import { aCompose } from '@opentf/std';
 
aCompose(
  val: unknown,
  ...fns: Function[]
): Promise<unknown>

Examples

await aCompose(
  1,
  (x) => Promise.resolve(x + 1),
  (x) => Promise.resolve(x * 5)
); //=> 6

Try

Learn

Why we need function composition?

  • The deep nesting of functions is hard to read.
  • It eliminates temporary variables.
  • Method chaining is limited, for Eg: await, yeild, etc.

Resources