Hyperlinkv0.8.0-beta.28

TxHashMap

TxHashMap.someconsteffect/TxHashMap.ts:1803
<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>

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)
})
combinators
export 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>
} = dual(
  2,
  <K, V>(
    self: TxHashMap<K, V>,
    predicate: (value: V, key: K) => boolean
  ): Effect.Effect<boolean> => TxRef.get(self.ref).pipe(Effect.map((map) => HashMap.some(map, predicate)))
)