MCPcopy Create free account
hub / github.com/Effect-TS/effect / flipEncoding

Function flipEncoding

packages/effect/src/SchemaAST.ts:4855–4864  ·  view source on GitHub ↗
(ast: AST, encoding: Encoding)

Source from the content-addressed store, hash-verified

4853export const toEncoded = (ast: AST): AST => toType(flip(ast))
4854
4855function flipEncoding(ast: AST, encoding: Encoding): AST {
4856 let from = replaceEncoding(ast, undefined)
4857 const reversed = encoding.map((link) => {
4858 const out = new Link(flip(from), link.transformation.flip())
4859 from = link.to
4860 return out
4861 }).reverse() as Arr.NonEmptyArray<Link>
4862 const to = flip(from)
4863 return replaceEncoding(to, to.encoding ? [...to.encoding, ...reversed] : reversed)
4864}
4865
4866/**
4867 * Swaps the decode and encode directions of an AST's {@link Encoding} chain.

Callers 1

flipASTFunction · 0.85

Calls 4

replaceEncodingFunction · 0.85
flipFunction · 0.70
flipMethod · 0.65
mapMethod · 0.45

Tested by

no test coverage detected