撰写

让你组成几个函数 f₀ f₁ … fₙ。它返回一个函数,它将 fₙ连续应用于其参数,然后将 fₙ₋₁应用于 fₙ的结果,依此类推。函数从右到左应用,如数学函数组成:(f ∘ g ∘ h)(x) = f(g(h(x)))

> ((compose sqrt +) 16 9)
5
> ((compose - sqrt) 16)
-4

每个函数的 arity 应该包括函数的右侧返回值的数量。最右边的功能决定了整个构图的灵活性。compose1 函数强制函数返回 1 值并期望 1 参数。但是,compose1 不限制最后一个函数的输入 arity,也不限制第一个函数的输出 arity。

[n input]--> first-function -->[1 output]--> ... last function -->[m output].

((compose + values) 1 2 3 4)
10
> ((compose1 + values) 1 2 3 4)
XX result arity mismatch;
 expected number of values not received
  expected: 1
  received: 4
  values...: