Worked examples showing Effect module patterns (TypeId, dual, Equal.symbol, Hash.symbol).
npm install @effect-native/patterns@effect-native/patternsHands-on study material for the Effect Native codebase. Each module in this
package illustrates the expectations described in the normative pattern library
(.patterns/*.md).
Thing is a deliberately small data type that demonstrates several of the
library-wide rules:
- Type identifiers: every instance carries a stable TypeId symbol so it
can be recognised safely across module boundaries.
- Structural protocols: the prototype implements Equal.symbol and
Hash.symbol, using Hash.cached plus sorted, deduplicated tags to keep hash
codes deterministic.
- Dual combinators: higher-order helpers like mapValue and addTag are
exposed with dual so they support both data-first and data-last styles.
- Pipeable: the prototype delegates to Effect's pipeArguments helper so
instances compose naturally with .pipe(...).
The accompanying tests in test/Thing.test.ts follow the@effect/vitest conventions from .patterns/testing-patterns.md, showing how
structured data (Data.struct) integrates with Equal/Hash.
``ts
import * as Thing from "@effect-native/patterns/Thing"
const todo = Thing.make({
id: "add-patterns-docs",
label: "Write README",
value: { done: false }
})
const updated = todo.pipe(
Thing.mapValue((value) => ({ ...value, done: true })),
Thing.addTag("docs")
)
`
Run pnpm --filter @effect-native/patterns test inside nix develop to execute
the worked examples.
List models a functional, singly-linked sequence with all of the idioms we
lean on in production code:
- Pipeable structure: every list is Pipeable, so you can chainEqual.symbol
transformations without reaching for helpers.
- Structural equality: the prototype implements andHash.symbol
by walking the nodes to ensure hashing follows value semantics.cons
- Dual combinators: helpers like , append, map, reduce, andforEachEffect
all use dual so they work in both data-first and data-lastforEachEffect
styles.
- Effect traversal: demonstrates how to loop over theEffect.gen
structure within , yielding each node sequentially.
The tests in test/List.test.ts include examples covering both pure and.patterns/testing-patterns.md
Effectful usage while applying the guardrails in .
Tree demonstrates how to build richer recursive data models:
- Structured construction: make accepts immutable child collections, andEqual.symbol
every node tracks its subtree size for quick introspection.
- Deep equality / hashing: the prototype walks child trees to implement
and Hash.symbol, ensuring structural comparison works acrossappendChild
nested data.
- Dual helpers: , map, and reduce all support data-firstdual
and data-last usage via , mirroring the conventions in the EffectforEachEffect
standard library.
- Effectful traversal: produces depth-first visitation withEffect.gen
index paths, showing how to integrate recursion with .
See test/Tree.test.ts` for executable examples that combine pure and Effectful
workloads.