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

Function intern

ark/type/runtime.ts:1551–1565  ·  view source on GitHub ↗
(
	table: InternTable,
	holes: readonly unknown[],
	create: () => value,
	// defaults a Type created first may not have checked
	defaults: readonly DefaultKey[] = []
)

Source from the content-addressed store, hash-verified

1549
1550// returns what it created before for the same holes
1551export const intern = <value>(
1552 table: InternTable,
1553 holes: readonly unknown[],
1554 create: () => value,
1555 // defaults a Type created first may not have checked
1556 defaults: readonly DefaultKey[] = []
1557): value => {
1558 for (const hole of holes) table = table.next(hole)
1559 if (
1560 table.value !== undefined &&
1561 defaults.some(key => !checkedDefaultOf(key).value)
1562 )
1563 create()
1564 return (table.value ??= create()) as value
1565}
1566
1567const tablesByHolder = /* @__PURE__ */ new InternTable()
1568

Callers 3

rekeyedFunction · 0.70
internInFunction · 0.70
internedFunction · 0.70

Calls 3

checkedDefaultOfFunction · 0.70
createFunction · 0.50
nextMethod · 0.45

Tested by

no test coverage detected