import type { Curried } from '../../compositions/curry.js'; import { type Purried, purry } from '../../compositions/purry.js'; import { _isIterable } from '../../controls/_guards.js'; import type { MaybePromise, Series, SyncSeries } from '../../controls/types.js'; function _syncSome(input: SyncSeries, test: (value: T) => boolean): boolean { for (const value of input) { if (test(value)) return true; } return false; } async function _asyncSome( input: Series, test: (value: Awaited) => MaybePromise, ): Promise { const awaited = await input; if (_isIterable(awaited)) { for (const value of awaited) { if (await test(await value)) return true; } } else { for await (const value of awaited) { if (await test(value)) return true; } } return false; } export function someSync( ...args: Parameters> ): ReturnType>; export function someSync( ...args: Parameters>> ): ReturnType>>; export function someSync( ...args: Parameters>> ): ReturnType>> { return purry(_syncSome)(...args); } export function someAsync( ...args: Parameters> ): ReturnType>; export function someAsync( ...args: Parameters>> ): ReturnType>>; export function someAsync( ...args: Parameters>> ): ReturnType>> { return purry(_asyncSome)(...args); } /** Determines whether at least one elements satisfy the specified test. */ export namespace some { export const sync = someSync; export const async = someAsync; }