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

Function formatTuple

packages/effect/src/SchemaAST.ts:1352–1377  ·  view source on GitHub ↗
(ast: TupleType)

Source from the content-addressed store, hash-verified

1350}
1351
1352const formatTuple = (ast: TupleType): string => {
1353 const formattedElements = ast.elements.map(String)
1354 .join(", ")
1355 return Arr.matchLeft(ast.rest, {
1356 onEmpty: () => `readonly [${formattedElements}]`,
1357 onNonEmpty: (head, tail) => {
1358 const formattedHead = String(head)
1359 const wrappedHead = formattedHead.includes(" | ") ? `(${formattedHead})` : formattedHead
1360
1361 if (tail.length > 0) {
1362 const formattedTail = tail.map(String).join(", ")
1363 if (ast.elements.length > 0) {
1364 return `readonly [${formattedElements}, ...${wrappedHead}[], ${formattedTail}]`
1365 } else {
1366 return `readonly [...${wrappedHead}[], ${formattedTail}]`
1367 }
1368 } else {
1369 if (ast.elements.length > 0) {
1370 return `readonly [${formattedElements}, ...${wrappedHead}[]]`
1371 } else {
1372 return `ReadonlyArray<${formattedHead}>`
1373 }
1374 }
1375 }
1376 })
1377}
1378
1379/**
1380 * @category guards

Callers 1

toStringMethod · 0.85

Calls 3

StringInterface · 0.85
joinMethod · 0.65
mapMethod · 0.65

Tested by

no test coverage detected