Packages@accelint/coreArray
some
Tests whether any elements in the array pass the given comparator.
Usage
import { some } from '@accelint/core/array/some';
// Check if any number is even
const hasEven = some((x: number) => x % 2 === 0)([1, 3, 4, 5]);
// true
const noEvens = some((x: number) => x % 2 === 0)([1, 3, 5]);
// falseReference
function some<T>(
comparator: (element: T) => boolean
): (arr: T[]) => booleanParameters
| Parameter | Type | Description |
|---|---|---|
comparator | (element: T) => boolean | Function called for each element. Returns true if element passes test, false otherwise. |
Returns
Returns a curried function that accepts an array and returns true if any element passes the comparator, false otherwise.
Type Parameters
T- The type of elements in the array
Examples
Example: Checking for conditions
import { some } from '@accelint/core/array/some';
interface Product {
name: string;
inStock: boolean;
}
const products: Product[] = [
{ name: 'Widget', inStock: false },
{ name: 'Gadget', inStock: true }
];
const anyAvailable = some((p: Product) => p.inStock)(products);
// trueExample: Finding specific values
import { some } from '@accelint/core/array/some';
const numbers = [1, 2, 3, 4, 5];
const hasNegative = some((n: number) => n < 0)(numbers);
// falseGood to know: Returns
falsefor an empty array. Short-circuits on first passing element, providing early exit optimization. This is a pure function with no side effects.