MCPcopy Index your code
hub / github.com/Effect-TS/effect / unify

Function unify

packages/effect/src/SchemaAST.ts:1613–1695  ·  view source on GitHub ↗
(candidates: ReadonlyArray<AST>)

Source from the content-addressed store, hash-verified

1611
1612/** @internal */
1613export const unify = (candidates: ReadonlyArray<AST>): Array<AST> => {
1614 const cs = sortCandidates(candidates)
1615 const out: Array<AST> = []
1616 const uniques: { [K in AST["_tag"] | "{}"]?: AST } = {}
1617 const literals: Array<LiteralValue | symbol> = []
1618 for (const ast of cs) {
1619 switch (ast._tag) {
1620 case "NeverKeyword":
1621 break
1622 case "AnyKeyword":
1623 return [anyKeyword]
1624 case "UnknownKeyword":
1625 return [unknownKeyword]
1626 // uniques
1627 case "ObjectKeyword":
1628 case "UndefinedKeyword":
1629 case "VoidKeyword":
1630 case "StringKeyword":
1631 case "NumberKeyword":
1632 case "BooleanKeyword":
1633 case "BigIntKeyword":
1634 case "SymbolKeyword": {
1635 if (!uniques[ast._tag]) {
1636 uniques[ast._tag] = ast
1637 out.push(ast)
1638 }
1639 break
1640 }
1641 case "Literal": {
1642 const type = typeof ast.literal
1643 switch (type) {
1644 case "string":
1645 case "number":
1646 case "bigint":
1647 case "boolean": {
1648 const _tag = literalMap[type]
1649 if (!uniques[_tag] && !literals.includes(ast.literal)) {
1650 literals.push(ast.literal)
1651 out.push(ast)
1652 }
1653 break
1654 }
1655 // null
1656 case "object": {
1657 if (!literals.includes(ast.literal)) {
1658 literals.push(ast.literal)
1659 out.push(ast)
1660 }
1661 break
1662 }
1663 }
1664 break
1665 }
1666 case "UniqueSymbol": {
1667 if (!uniques["SymbolKeyword"] && !literals.includes(ast.symbol)) {
1668 literals.push(ast.symbol)
1669 out.push(ast)
1670 }

Callers 7

securityDecodeFunction · 0.85
toHandledFunction · 0.85
foreign.test.tsFile · 0.85
foreign.test.tsFile · 0.85
foreign.test.tsFile · 0.85
foreign.test.tsFile · 0.85
UnionClass · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…