@panac/pipe-compose
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

pipe and compose function

pipe

function sleep() {
    return new Promise((resolve, reject) => {
      setTimeout(() => resolve(), 1000);
    });
  }

  const testtest = async () => {
    const fn1 = async (val: string) => {
      await sleep();
      return `fn1(${val})`;
    };
    const fn2 = async (val: string) => {
      await sleep();
      return `fn2(${val})`;
    };
    const fn3 = async (val: string) => {
      await sleep();
      return `fn3(${val})`;
    };
    return pipe(
      fn1,
      fn2,
      fn3
    )('inner');
  };

  await testtest() // 'fn3(fn2(fn1(inner)))'

compose

function sleep() {
    return new Promise((resolve, reject) => {
      setTimeout(() => resolve(), 1000);
    });
  }

  const testtest = async () => {
    const fn1 = async (val: string) => {
      await sleep();
      return `fn1(${val})`;
    };
    const fn2 = async (val: string) => {
      await sleep();
      return `fn2(${val})`;
    };
    const fn3 = async (val: string) => {
      await sleep();
      return `fn3(${val})`;
    };
    return (await compose(
      fn1,
      fn2,
      fn3
    ))('inner');
  };

  await testtest() // 'fn1(fn2(fn3(inner)))'

Readme

Keywords

none

Package Sidebar

Install

npm i @panac/pipe-compose

Weekly Downloads

0

Version

1.0.0

License

BSD-3-Clause

Unpacked Size

11.4 kB

Total Files

29

Last publish

Collaborators

  • panac