over
util
Creates a function that invokes iteratees with the arguments it receives and returns their results.
Installation
Import
import { over } from '@tulx/utils';Source Code
Implementation
/**
* Creates a function that invokes iteratees with the arguments it receives and returns their results.
*
* @param iteratees - The iteratees to invoke.
* @returns Returns the new function.
*
* @example
* ```ts
* const func = over([Math.max, Math.min]);
* func(1, 2, 3, 4); // [4, 1]
* ```
*/
export function over<T extends unknown[]>(
iteratees: readonly ((...args: T) => unknown)[]
): (...args: T) => unknown[] {
return function (...args: T): unknown[] {
return iteratees.map((iteratee) => iteratee(...args));
};
}
Example
import { over } from '@tulx/utils';
const func = over([Math.max, Math.min]);
func(1, 2, 3, 4); // [4, 1]Related Functions
attempt
Attempts to invoke func, returning either the result or the caught error object.
bindAll
Binds methods of an object to the object itself, overwriting the existing method.
cond
Creates a function that iterates over pairs and invokes the corresponding function of the first predicate to return truthy.
conforms
Creates a function that invokes the predicate properties of source with the corresponding property values of a given object.
constant
Creates a function that returns value.
defaultTo
Checks value to determine whether a default value should be returned in its place.