Skip to content

flip

Summary

Swap the first two arguments of a function.

Description

Take a function fn of arity 2 (or more) and return a curried version of it where the first two parameters have been swapped.

Examples

1
2
3
4
5
6
7
8
9
const x = (a, b, c) => a + b + c;

x('foo', 'bar', 'baz');
//=> 'foobarbaz'

const y = flip(x);

y('foo')('bar', 'baz');
//=> 'barfoobaz'

Parameters

Name Type Description
fn function

Return

function