effect-io-ai

Package: effect
Module: TxHashMap

TxHashMap.some

Checks whether at least one entry in the TxHashMap satisfies the given predicate.

Example (Checking whether some entries match)

import { Effect, TxHashMap } from "effect"

const program = Effect.gen(function*() {
  // Create a product inventory
  const inventory = yield* TxHashMap.make(
    ["laptop", { price: 999, stock: 5 }],
    ["mouse", { price: 29, stock: 50 }],
    ["keyboard", { price: 79, stock: 0 }]
  )

  // Check if any products are expensive
  const hasExpensiveProducts = yield* TxHashMap.some(
    inventory,
    (product) => product.price > 500
  )
  console.log(hasExpensiveProducts) // true

  // Check if any products are out of stock
  const hasOutOfStock = yield* TxHashMap.some(
    inventory,
    (product) => product.stock === 0
  )
  console.log(hasOutOfStock) // true

  // Data-last usage with pipe
  const hasAffordableItems = yield* inventory.pipe(
    TxHashMap.some((product) => product.price < 50)
  )
  console.log(hasAffordableItems) // true (mouse is $29)
})

Signature

declare const some: { <K, V>(predicate: (value: V, key: K) => boolean): (self: TxHashMap<K, V>) => Effect.Effect<boolean>; <K, V>(self: TxHashMap<K, V>, predicate: (value: V, key: K) => boolean): Effect.Effect<boolean>; }

Source

Since v4.0.0