# compose

### 说明

从右往左执行处理器函数, 与 [pipe()](https://ddzy.gitbook.io/ts-utility-plugins-docs/utility/utility-function/pipe) 方法相反

### 源码

<https://github.com/ddzy/ts-utility-plugins/tree/master/src/ddzy/utility/function/compose>

### 用法

{% code title="compose.test.ts" %}

```typescript
import { compose } from "../../utility/function/compose";

describe('compose', () => {
  test('compose should invoke function from right to left', () => {
    function func1() {
      return func2() * 2;
    }
    function func2() {
      return func3() * 3;
    }
    function func3() {
      return 4;
    }

    function func4() {
      return func5() + '*' + 'yang';
    }
    function func5() {
      return func6() + '*' + 'zhao';
    }
    function func6() {
      return 'duan';
    }

    const received = {
      s1: [func1, func2, func3],
      s2: [func4, func5, func6],
    };
    const expected = {
      p1: 24,
      p2: 'duan*zhao*yang',
    };

    const r1 = compose(...received.s1);
    const r2 = compose(...received.s2);

    expect(r1).toBe(expected.p1);
    expect(r2).toBe(expected.p2);
  });
});
```

{% endcode %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://ddzy.gitbook.io/ts-utility-plugins-docs/utility/utility-function/compose.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
