Functions

Browse all available utility functions by category

function

after

The opposite of before; this method creates a function that invokes func once it's called n or more times.

Example:

const saves = ['profile', 'settings'];
function

ary

Creates a function that invokes func, with up to n arguments, ignoring any additional arguments.

Example:

map(['6', '8', '10'], ary(parseInt, 1)); // [6, 8, 10]
function

before

Creates a function that invokes func, with the this binding and arguments of the created function, while it's called less than n times.

Example:

jQuery(element).on('click', before(5, addContactToList));
function

bind

Creates a function that invokes func with the this binding of thisArg and partials prepended to the arguments it receives.

Example:

const greet = function(greeting: string, punctuation: string) {
function

bindKey

Creates a function that invokes the method at object[key] with partials prepended to the arguments it receives.

Example:

const object = {
function

curry

Creates a function that accepts arguments of func and either invokes func returning its result, or returns a function that accepts the remaining arguments.

Example:

const abc = (a: string, b: string, c: string) => [a, b, c];
function

curryRight

This method is like curry except that arguments are applied to func in the manner of partialRight instead of partial.

Example:

const abc = (a: string, b: string, c: string) => [a, b, c];
function

debounce

Creates a debounced function that delays invoking func until after wait milliseconds have elapsed since the last time the debounced function was invoked.

Example:

const debounced = debounce(() => console.log('hello'), 1000);
function

defer

Defers invoking the func until the current call stack has cleared.

Example:

defer((text: string) => console.log(text), 'deferred'); // Logs 'deferred' after one millisecond.
function

delay

Invokes func after wait milliseconds.

Example:

delay((text: string) => console.log(text), 1000, 'later'); // Logs 'later' after one second.
function

flip

Creates a function that invokes func with arguments reversed.

Example:

const flipped = flip((...args: unknown[]) => args);
function

memoize

Creates a function that memoizes the result of func.

Example:

const object = { 'a': 1, 'b': 2 };
function

negate

Creates a function that negates the result of the predicate func.

Example:

const isEven = (n: number) => n % 2 === 0;
function

once

Creates a function that is restricted to invoking func once.

Example:

const initialize = once(() => console.log('initialized'));
function

overArgs

Creates a function that invokes func with its arguments transformed.

Example:

function doubled(n: number) {
function

partial

Creates a function that invokes func with partials prepended to the arguments it receives.

Example:

function greet(greeting: string, name: string) {
function

partialRight

This method is like partial except that partials are appended to the arguments it receives.

Example:

function greet(greeting: string, name: string) {
function

rearg

Creates a function that invokes func with arguments arranged according to the specified indexes.

Example:

const rearged = rearg((a: string, b: string, c: string) => [a, b, c], [2, 0, 1]);
function

rest

Creates a function that invokes func with the this binding of the created function and arguments from start and beyond provided as an array.

Example:

const say = rest((what: string, names: string[]) => what + ' ' + names.join(', '));
function

spread

Creates a function that invokes func with the array of arguments provided to the created function.

Example:

const say = spread((who: string, what: string) => who + ' says ' + what);
function

throttle

Creates a throttled function that only invokes func at most once per every wait milliseconds.

Example:

const throttled = throttle(() => console.log('hello'), 1000);
function

unary

Creates a function that accepts up to one argument, ignoring any additional arguments.

Example:

map(['6', '8', '10'], unary(parseInt)); // [6, 8, 10]
function

wrap

Creates a function that provides value to wrapper as its first argument.

Example:

const p = wrap(escape, (func: typeof escape, text: string) => '<p>' + func(text) + '</p>');