function

Methods

static apply(fn, args) → {*}

Functional `apply` function (takes no context).
Parameters:
Name Type Description
fn function
args Array | *
Returns:
*

static call(fn, …args) → {*}

Functional `call` function (takes no context).
Parameters:
Name Type Attributes Description
fn function
args * <repeatable>
Returns:
*

static compose(…args) → {function|function}

Composes all functions passed in from right to left passing each functions return value to the function on the left of itself.
Parameters:
Name Type Attributes Description
args Object <repeatable>
Returns:
  • function
  • function

static curry(fn, …argsToCurry) → {function}

Curries a function based on it's defined arity (note: rest args param (`...rest`) are not counted in arity).
Parameters:
Name Type Attributes Description
fn function
argsToCurry * <repeatable>
Returns:
function

static curry2(fn) → {function}

Curries a function up to an arity of 2 (won't call function until 2 or more args).
Parameters:
Name Type Description
fn function
Returns:
function

static curry3(fn) → {function}

Curries a function up to an arity of 3 (won't call function until 3 or more args).
Parameters:
Name Type Description
fn function
Returns:
function

static curry4(fn) → {function}

Curries a function up to an arity of 4 (won't call function until 4 or more args).
Parameters:
Name Type Description
fn function
Returns:
function

static curry5(fn) → {function}

Curries a function up to an arity of 5 (won't call function until 5 or more args).
Parameters:
Name Type Description
fn function
Returns:
function

static curryN(executeArity, fn, …argsToCurry) → {function}

Curries a function up to a given arity.
Parameters:
Name Type Attributes Description
executeArity Number
fn function
argsToCurry * <repeatable>
Throws:
- When `fn` is not a function.
Type
Error
Returns:
function

static flip(fn) → {function}

Flips a function's first and second arguments and and returns a new function requiring said arguments in reverse.
Parameters:
Name Type Description
fn function
Returns:
function

static flip3(fn) → {function}

Same as `flip` except returns a flipped function of arity 3.
Parameters:
Name Type Description
fn function
Returns:
function

static flip4(fn) → {function}

Same as `flip` except returns a flipped function of arity 4.
Parameters:
Name Type Description
fn function
Returns:
function

static flip5(fn) → {function}

Same as `flip` except returns a flipped function of arity 5.
Parameters:
Name Type Description
fn function
Returns:
function

static flipN(fn) → {function}

Returns a curried function requiring given functions arguments in reverse (returned function expects 2 or more variables (curried at 2 or more args)).
Parameters:
Name Type Description
fn function
Returns:
function

static fnOrError(symbolName, f) → {function}

Returns a function or throws an error if given `f` is not a function.
Parameters:
Name Type Description
symbolName String Error message prefix.
f function | * Expected function.
Throws:
- Error if `f` is not of `function`
Type
Error
Returns:
function

static id(x) → {*}

Returns passed in parameter.
Parameters:
Name Type Description
x *
Returns:
*

static negateF(fn) → {function}

Negates a function that takes one/no argument.
Parameters:
Name Type Description
fn function
Returns:
function

static negateFN(fn) → {function}

Returns a negated version of given function. Returned function is variadiac (takes one or more arguments).
Parameters:
Name Type Description
fn function
Returns:
function

static noop() → {undefined}

No-op ('op' as in 'operation') - Performs no operation 'always' (good for places where a value should always be a function etc.).
Returns:
undefined

static toFunction(x) → {function}

If given value is not a function, wraps it an 'identity' function (function that returns given value untouched) else returns given value. (useful in functional composition).
Parameters:
Name Type Description
x function | any
Returns:
function

static trampoline(fn, fnNameopt) → {*}

Trampolines function calls in order to avoid stack overflow errors on recursive function calls; Tail recursion replacement.
Parameters:
Name Type Attributes Description
fn function Function to trampoline.
fnName String <optional>
Optionally restrict trampolining only to function with specific name.
Returns:
* - - Finally returned value.
Example
// Instead of ... (which is prone to stack-overflow in
//   non-tail-call optimized environments (es5-es3))
const factorial = n => n > 1 ? n * factorial(n - 1) : 1;

// We do
const

 factorialProcess = (n, agg = 1) => {
     n > 1 ? () => factorialProcess(n - 1, agg * n) : agg,
 },

 factorial = trampoline(factorialProcess)
 // will not overflow as we are performing tail call elimination
 // by returning thunks from factorial process which run in `while` loop
 // within `trampoline`.

 ;

static until(predicate, operation, typeInstance) → {*}

Run `operation` until predicate returns `true` (like a functional version of a while loop).
Parameters:
Name Type Description
predicate function :: a -> Boolean
operation function :: a -> a
typeInstance * :: * - A monoidal zero or some starting point.
Returns:
* - - What ever type `typeInstance` is