Standard Toolkit
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]);
// false

Reference

function some<T>(
  comparator: (element: T) => boolean
): (arr: T[]) => boolean

Parameters

ParameterTypeDescription
comparator(element: T) => booleanFunction 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);
// true

Example: 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);
// false

Good to know: Returns false for an empty array. Short-circuits on first passing element, providing early exit optimization. This is a pure function with no side effects.

  • every - Test if all elements pass comparator
  • filter - Get all elements matching predicate
  • find - Find first element matching predicate

On this page