flip
Swap the only two arguments of a function
63 bytes
Usage
Return a new function that swaps the only two arguments of the original function. This is most useful for reversing the order of a “comparator” (i.e. a function used for sorting).
import * as import _
_ from 'radashi'
const const subtract: (a: number, b: number) => number
subtract = (a: number
a: number, b: number
b: number) => a: number
a - b: number
b
const subtract: (a: number, b: number) => number
subtract(1, 2) // => -1import _
_.flip<[a: number, b: number], number>(fn: (a: number, b: number) => number): (args_0: number, args_1: number) => numberexport flip
Flip the first two arguments of a function.
flip(const subtract: (a: number, b: number) => number
subtract)(1, 2) // => 1Note that functions with more than two arguments are not supported.