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

Method parse

ark/type/fn.ts:84–104  ·  view source on GitHub ↗
(...signature: unknown[])

Source from the content-addressed store, hash-verified

82export class InternalFnParser extends Callable<(...args: unknown[]) => Fn> {
83 constructor($: InternalScope) {
84 const parse = (...signature: unknown[]) => {
85 const returnOperatorIndex = signature.indexOf(":")
86 const lastParamIndex =
87 returnOperatorIndex === -1 ?
88 signature.length - 1
89 : returnOperatorIndex - 1
90
91 const paramDefs = signature.slice(0, lastParamIndex + 1)
92
93 const paramTuple = $.parse(paramDefs)
94
95 let returnType: BaseRoot = $.intrinsic.unknown
96
97 if (returnOperatorIndex !== -1) {
98 if (returnOperatorIndex !== signature.length - 2)
99 return throwParseError(badFnReturnTypeMessage)
100 returnType = $.parse(signature[returnOperatorIndex + 1])
101 }
102
103 return (impl: Fn) => new InternalTypedFn(impl, paramTuple, returnType)
104 }
105
106 // `raw` is an alias of `fn` itself with no type-level validation. It must
107 // reference `parse` directly rather than `$.fn`, which is still being

Callers 15

getParamValueFunction · 0.45
addEnvConfigFunction · 0.45
getErrorLinesFunction · 0.45
countVariantsFunction · 0.45
highlightLayerFunction · 0.45
target.tsFile · 0.45
errorLens.tsFile · 0.45
readExpectedFunction · 0.45
readDifferencesFunction · 0.45
readActualDirFunction · 0.45
createTokenizerFunction · 0.45

Calls 1

throwParseErrorFunction · 0.90

Tested by 15

failureOfFunction · 0.36
versionOfFunction · 0.36
partitionOfFunction · 0.36
commandFunction · 0.36
decodeFunction · 0.36
namesOfFunction · 0.36
runWorldFunction · 0.36
divergedFunction · 0.36
sourceLineOfFunction · 0.36
markStoredFunction · 0.36
errorsOfFunction · 0.36
shapeOfFunction · 0.36