Module: Core/Lambda

Core/Lambda

Provides pure functional combinators.

Source:

Members

<static> apply

(a → b) → a → b

Applies a function to an argument.

Source:
Example
var inc = (a) => a + 1
apply(inc)(3)      // => 4

<static> compose

(b → c) → (a → b) → (a → c)

Composes two functions together.

Source:
Example
var inc    = (a) => a + 1
var square = (a) => a * a
compose(inc)(square)(2)    // => 5,        inc(square(2))

<static> constant

a → b → a

The constant combinator. Always returns the first argument it's given.

Source:
Example
constant(3)(2)             // => 3
constant('foo')([1])       // => 'foo'

<static> curry

Number → ((a1, a2, ..., aN) → b) → (a1 → a2 → ... → aN → b)

Transforms any function on tuples into a curried function.

Source:
Example
var sub3 = (a, b, c) => a - b - c
curry(3, sub3)(5)(2)(1)   // => 2

<static> flip

(a → b → c) → (b → a → c)

Inverts the order of the parameters of a binary function.

Source:
Example
var subtract = (a) => (b) => a - b
subtract(3)(2)             // => 1
flip(subtract)(3)(2)       // => -1

<static> identity

a → a

The identity combinator. Always returns the argument it's given.

Source:
Example
identity(3)        // => 3
identity([1])      // => [1]

<static> spread

(a1 → a2 → ... → aN → b) → (#[a1, a2, ..., aN) → b)

Transforms a curried function into one accepting a list of arguments.

Source:
Example
var add = (a) => (b) => a + b
spread(add)([3, 2])        // => 5

<static> uncurry

(a1 → a2 → ... → aN → b) → ((a1, a2, ..., aN) → b)

Transforms a curried function into a function on tuples.

Source:
Example
var add = (a) => (b) => a + b
uncurry(add)(3, 2)         // => 5

<static> upon

(b → b → c) → (a → b) → (a → a → c)

Applies an unary function to both arguments of a binary function.

Source:
Example
var xss = [[1, 2], [3, 1], [-2, 4]]
sortBy(upon(compare, first))