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

Function uniqueFlatRefs

ark/schema/node.ts:2166–2176  ·  view source on GitHub ↗
(refs: FlatRef[])

Source from the content-addressed store, hash-verified

2164
2165// refs are equal only at the same path
2166export const uniqueFlatRefs = (refs: FlatRef[]): FlatRef[] => {
2167 const refsByPath = new Map<string, FlatRef[]>()
2168 return refs.filter(ref => {
2169 const atPath = refsByPath.get(ref.propString)
2170 if (!atPath) refsByPath.set(ref.propString, [ref])
2171 else if (atPath.some(existing => existing.node.equals(ref.node)))
2172 return false
2173 else atPath.push(ref)
2174 return true
2175 })
2176}
2177
2178export const appendUniqueNodes = <node extends BaseNode>(
2179 existing: node[] | undefined,

Callers 2

initFlatMethod · 0.90
initFlatFunction · 0.85

Calls 5

filterMethod · 0.80
getMethod · 0.65
equalsMethod · 0.65
setMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected