Back to Functions

overSome

util

Creates a function that checks if any of the predicates return truthy when invoked with the arguments it receives.

Installation

Import
import { overSome } from '@tulx/utils';

Source Code

Implementation
/**
 * Creates a function that checks if any of the predicates return truthy when invoked with the arguments it receives.
 *
 * @param predicates - The predicates to check.
 * @returns Returns the new function.
 *
 * @example
 * ```ts
 * const func = overSome([Boolean, isFinite]);
 * func('1'); // true
 * func(null); // true
 * func(NaN); // false
 * ```
 */
export function overSome<T extends unknown[]>(
  predicates: readonly ((...args: T) => boolean)[]
): (...args: T) => boolean {
  return function (...args: T): boolean {
    return predicates.some((predicate) => predicate(...args));
  };
}

Example

import { overSome } from '@tulx/utils';

const func = overSome([Boolean, isFinite]);
func('1'); // true
func(null); // true
func(NaN); // false

Related Functions