MCPcopy Create free account
hub / github.com/arktypeio/arktype / intersectIntersections

Function intersectIntersections

ark/sets/roots/intersection.ts:113–156  ·  view source on GitHub ↗
(
	l: Intersection.Inner,
	r: Intersection.Inner,
	ctx: IntersectionContext,
	flatten = flattenConstraints
)

Source from the content-addressed store, hash-verified

111}
112
113const intersectIntersections = (
114 l: Intersection.Inner,
115 r: Intersection.Inner,
116 ctx: IntersectionContext,
117 flatten = flattenConstraints
118): BaseRoot | Disjoint => {
119 const baseInner: Intersection.Inner.mutable = {}
120
121 const lBasis = l.proto ?? l.domain
122 const rBasis = r.proto ?? r.domain
123 const basisResult =
124 lBasis ?
125 rBasis ?
126 (intersectOrPipeNodes(
127 lBasis,
128 rBasis,
129 ctx
130 ) as nodeOfKind<Intersection.BasisKind>)
131 : lBasis
132 : rBasis
133 if (basisResult instanceof Disjoint) return basisResult
134
135 if (basisResult) baseInner[basisResult.kind] = basisResult as never
136
137 const lConstraints = flatten(l)
138 const rConstraints = flatten(r)
139
140 if (lBasis ? !rBasis : rBasis) {
141 const disjoint =
142 lBasis ?
143 disjointFromImplied(rConstraints, lBasis, ctx)?.invert()
144 : disjointFromImplied(lConstraints, rBasis!, ctx)
145 if (disjoint) return disjoint
146 }
147
148 return intersectConstraints({
149 kind: "intersection",
150 baseInner,
151 l: lConstraints,
152 r: rConstraints,
153 roots: [],
154 ctx
155 })
156}
157
158// a discriminant prunes the basis its case has checked, leaving constraints
159// that hold only of what the basis they imply allows, so they're disjoint from

Callers 2

intersection.tsFile · 0.85
constrainIntersectionFunction · 0.85

Calls 4

intersectConstraintsFunction · 0.90
flattenFunction · 0.85
disjointFromImpliedFunction · 0.85
invertMethod · 0.80

Tested by

no test coverage detected