Hyperlinkv0.8.0-beta.28

Array

Array.someconsteffect/Array.ts:4173
<A>(predicate: (a: NoInfer<A>, i: number) => boolean): (
  self: ReadonlyArray<A>
) => self is NonEmptyReadonlyArray<A>
<A>(
  self: ReadonlyArray<A>,
  predicate: (a: A, i: number) => boolean
): self is NonEmptyReadonlyArray<A>

Checks whether at least one element satisfies the predicate. Narrows the type to NonEmptyReadonlyArray on success.

Example (Testing for any match)

import { Array } from "effect"

console.log(Array.some([1, 3, 4], (x) => x % 2 === 0)) // true
console.log(Array.some([1, 3, 5], (x) => x % 2 === 0)) // false
Source effect/Array.ts:417310 lines
export const some: {
  <A>(
    predicate: (a: NoInfer<A>, i: number) => boolean
  ): (self: ReadonlyArray<A>) => self is NonEmptyReadonlyArray<A>
  <A>(self: ReadonlyArray<A>, predicate: (a: A, i: number) => boolean): self is NonEmptyReadonlyArray<A>
} = dual(
  2,
  <A>(self: ReadonlyArray<A>, predicate: (a: A, i: number) => boolean): self is NonEmptyReadonlyArray<A> =>
    self.some(predicate)
)