# chain

URL: https://caijiao.org/radash/curry/chain
Source: docs/radash/curry/chain.md
Description: 创建按顺序运行的函数链 链接函数将导致它们一个接一个地执行，将每个函数的输出作为下一个函数的输入，最后返回最终输出

创建按顺序运行的函数链


## 基本用法

链接函数将导致它们一个接一个地执行，将每个函数的输出作为下一个函数的输入，最后返回最终输出。
```ts
import { chain } from 'radash'

const add = (y: number) => (x: number) => x + y
const mult = (y: number) => (x: number) => x * y
const addFive = add(5)
const double = mult(2)

const chained = chain(addFive, double)

chained(0) // => 10
chained(7) // => 24
```

### 示例
```ts
import { chain } from 'radash'

type Deity = { 
  name: string
  rank: number 
}

const gods: Deity[] = [
  { rank: 8, name: 'Ra' },
  { rank: 7, name: 'Zeus' },
  { rank: 9, name: 'Loki' }
]

const getName = (god: Deity) => god.name
const upperCase = (text: string) => text.toUpperCase() as Uppercase<string>

const getUpperName = chain(
  getName, 
  upperCase
)

getUpperName(gods[0])       // => 'RA'
gods.map(getUpperName)      // => ['RA', 'ZEUS', 'LOKI']
```
