The goog.functions Namespace

.FALSE {function(...): boolean}

Always returns false.

.NULL {function(...): null}

Always returns NULL.

.TRUE {function(...): boolean}

Always returns true.

.and(var_args)

Creates a function that returns true if each of its components evaluates to true. The components are evaluated in order, and the evaluation will be short-circuited as soon as a function returns false. For example, (goog.functions.and(f, g))(x) is equivalent to f(x) && g(x).

var_args {...Function}
A list of functions.
returns {!Function}
A function that ANDs its component functions.

.compose(var_args)

Creates the composition of the functions passed in. For example, (goog.functions.compose(f, g))(a) is equivalent to f(g(a)).

var_args {...Function}
A list of functions.
returns {!Function}
The composition of all inputs.

.constant(retValue)

Creates a function that always returns the same value.

retValue {*}
The value to return.
returns {!Function}
The new function.

.create(constructor, var_args)

Generic factory function to construct an object given the constructor and the arguments. Intended to be bound to create object factories. Callers should cast the result to the appropriate type for proper type checking by the compiler.

constructor {!Function}
The constructor for the Object.
var_args {...*}
The arguments to be passed to the constructor.
returns {!Object}
A new instance of the class given in {@code constructor}.

.error(message)

Creates a function that always throws an error with the given message.

message {string}
The error message.
returns {!Function}
The error-throwing function.

.identity(opt_returnValue, var_args)

A simple function that returns the first argument of whatever is passed into it.

opt_returnValue {*=}
The single value that will be returned.
var_args {...*}
Optional trailing arguments. These are ignored.
returns {?}
The first argument passed in, or undefined if nothing was passed. We can't know the type -- just pass it along without type.

.lock(f, opt_numArgs)

Given a function, create a function that keeps opt_numArgs arguments and silently discards all additional arguments.

f {Function}
The original function.
opt_numArgs {number=}
The number of arguments to keep. Defaults to 0.
returns {!Function}
A version of f that only keeps the first opt_numArgs arguments.

.not(f)

Creates a function that returns the Boolean opposite of a provided function. For example, (goog.functions.not(f))(x) is equivalent to !f(x).

f {!Function}
The original function.
returns {!Function}
A function that delegates to f and returns opposite.

.or(var_args)

Creates a function that returns true if any of its components evaluates to true. The components are evaluated in order, and the evaluation will be short-circuited as soon as a function returns true. For example, (goog.functions.or(f, g))(x) is equivalent to f(x) || g(x).

var_args {...Function}
A list of functions.
returns {!Function}
A function that ORs its component functions.

.sequence(var_args)

Creates a function that calls the functions passed in in sequence, and returns the value of the last function. For example, (goog.functions.sequence(f, g))(x) is equivalent to f(x),g(x).

var_args {...Function}
A list of functions.
returns {!Function}
A function that calls all inputs in sequence.

.withReturnValue(f, retValue)

Given a function, create a new function that swallows its return value and replaces it with a new one.

f {Function}
A function.
retValue {*}
A new return value.
returns {!Function}
A new function.