Guidance for facet `effect/Schema#composition` focused on APIs like HashMap, HashMapIso, and compose. Load after `effect-skill-router` when this facet is the primary owner.
name: effect-facet-schema-composition
description: Guidance for facet effect/Schema#composition focused on APIs like HashMap, HashMapIso, and compose. Load after effect-skill-router when this facet is the primary owner.
Effect Facet Schema#composition
Owned scope
Owns only effect/Schema#composition.
Parent module: effect/Schema.
What it is for
struct/union/record/tuple composition. Module-specific APIs and usage patterns for Effect programs.
API quick reference
HashMap
HashMapIso
compose
SchemaPart
ReadonlyMap
$ReadonlyMap
ReadonlyMapIso
Full API list: references/api-reference.md
How to use it
Keep work focused on the composition concern for effect/Schema.
Prefer pipe-based composition to keep transformations explicit and testable.
Use schema/codec APIs to validate inputs at boundaries before business logic.
Starter example
import { Schema } from "effect"
// Define custom hook functions for error formatting
const leafHook = (issue: any) => {
switch (issue._tag) {
case "InvalidType":
return "Expected different type"
case "InvalidValue":
return "Invalid value provided"
case "MissingKey":
return "Required property missing"
case "UnexpectedKey":
return "Unexpected property found"
case "Forbidden":
return "Operation not allowed"
case "OneOf":
return "Multiple valid options available"
default:
return "Validation error"
}
}
// Create a standard schema from a regular schema
const PersonSchema = Schema.Struct({
Common pitfalls
Prefer explicit, typed combinators over ad-hoc casting or unchecked assumptions.
Not covered here
Sibling facets under the same parent are out of scope: