Skip to content

some() function

如果 Iterable/AsyncIterable 中的任何值通过 f 真值测试,则返回 true。

Signature:

typescript
declare function some<A extends readonly []>(f: Arrow, iterable: A): false;

Example

ts
some((a) => a, [null, 0, 1, false]); // true

// with pipe
pipe(
  [
    { id: 1, age: 27 },
    { id: 2, age: 36 },
    { id: 3, age: 42 },
  ],
  map((user) => user.age),
  some((age) => age > 40),
); // true

await pipe(
  Promise.resolve([
    { id: 1, age: 27 },
    { id: 2, age: 36 },
    { id: 3, age: 42 },
  ]),
  map((user) => user.age),
  some((age) => age > 40),
); // true

// with toAsync
await pipe(
  [
    Promise.resolve({ id: 1, age: 27 }),
    Promise.resolve({ id: 2, age: 36 }),
    Promise.resolve({ id: 3, age: 42 }),
  ],
  toAsync,
  map((user) => user.age),
  some((age) => age > 40),
); // true

Try It

see pipe, toAsync, map

Open Source Code

Released under the Apache-2.0 License.