Hyperlinkv0.8.0-beta.28

Trie

Trie.reduceconsteffect/Trie.ts:660
<Z, V>(zero: Z, f: (accumulator: Z, value: V, key: string) => Z): (
  self: Trie<V>
) => Z
<Z, V>(
  self: Trie<V>,
  zero: Z,
  f: (accumulator: Z, value: V, key: string) => Z
): Z

Reduces a state over the entries of the Trie.

Example (Reducing entries)

import { Trie } from "effect"
import * as assert from "node:assert"

const trie = Trie.empty<number>().pipe(
  Trie.insert("shells", 0),
  Trie.insert("sells", 1),
  Trie.insert("she", 2)
)

assert.equal(
  trie.pipe(
    Trie.reduce(0, (acc, n) => acc + n)
  ),
  3
)
assert.equal(
  trie.pipe(
    Trie.reduce(10, (acc, n) => acc + n)
  ),
  13
)
assert.equal(
  trie.pipe(
    Trie.reduce("", (acc, _, key) => acc + key)
  ),
  "sellssheshells"
)
folding
Source effect/Trie.ts:6604 lines
export const reduce: {
  <Z, V>(zero: Z, f: (accumulator: Z, value: V, key: string) => Z): (self: Trie<V>) => Z
  <Z, V>(self: Trie<V>, zero: Z, f: (accumulator: Z, value: V, key: string) => Z): Z
} = TR.reduce