MCPcopy Create free account
hub / github.com/Effect-TS/effect / walk

Function walk

packages/effect/src/Schema.ts:6286–6313  ·  view source on GitHub ↗
(schema: Constraint)

Source from the content-addressed store, hash-verified

6284 return Object.assign(self, { cases, discriminants, isAnyOf, guards, match }) as any
6285
6286 function walk(schema: Constraint) {
6287 const ast = schema.ast
6288
6289 if (
6290 SchemaAST.isUnion(ast) && "members" in schema && globalThis.Array.isArray(schema.members) &&
6291 schema.members.every(isSchema)
6292 ) {
6293 return schema.members.forEach(walk)
6294 }
6295
6296 const sentinels = SchemaAST.collectSentinels(ast)
6297 if (sentinels.length > 0) {
6298 const literal = sentinels.find((s) => s.key === tag)?.literal
6299 if (Predicate.isPropertyKey(literal)) {
6300 const key = typeof literal === "number" ? globalThis.String(literal) : literal
6301 if (discriminantKeys.has(key)) {
6302 throw new globalThis.Error(`Duplicate discriminant: ${globalThis.String(literal)}`)
6303 }
6304 discriminantKeys.add(key)
6305 discriminants.push(literal)
6306 InternalRecord.assignProperty(cases, literal, schema)
6307 InternalRecord.assignProperty(guards, literal, is(toType(schema)))
6308 return
6309 }
6310 }
6311
6312 throw new globalThis.Error("No literal or unique symbol found")
6313 }
6314
6315 function match() {
6316 if (arguments.length === 1) {

Callers 3

toTaggedUnionFunction · 0.70
DiscoveryClass · 0.50
readDirectoryFunction · 0.50

Calls 7

toTypeInterface · 0.85
pushMethod · 0.80
isFunction · 0.70
forEachMethod · 0.65
addMethod · 0.65
findMethod · 0.45
hasMethod · 0.45

Tested by

no test coverage detected