Hyperlinkv0.8.0-beta.28

Function

Function.flipconsteffect/Function.ts:454
<A extends Array<unknown>, B extends Array<unknown>, C>(
  f: (...a: A) => (...b: B) => C
): (...b: B) => (...a: A) => C

Reverses the order of arguments for a curried function.

When to use

Use to adapt a curried function when its argument groups need to be supplied in the opposite order.

Example (Flipping curried arguments)

import { Function } from "effect"
import * as assert from "node:assert"

const f = (a: number) => (b: string) => a - b.length

assert.deepStrictEqual(Function.flip(f)("aaa")(2), -1)
combinators
export const flip = <A extends Array<unknown>, B extends Array<unknown>, C>(
  f: (...a: A) => (...b: B) => C
): (...b: B) => (...a: A) => C =>
(...b) =>
(...a) => f(...a)(...b)