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

Function flipEncoding

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

Source from the content-addressed store, hash-verified

3741})
3742
3743function flipEncoding(ast: AST, encoding: Encoding): AST {
3744 const links = encoding
3745 const len = links.length
3746 const last = links[len - 1]
3747 const ls: Arr.NonEmptyArray<Link> = [
3748 new Link(flip(replaceEncoding(ast, undefined)), links[0].transformation.flip())
3749 ]
3750 for (let i = 1; i < len; i++) {
3751 ls.unshift(new Link(flip(links[i - 1].to), links[i].transformation.flip()))
3752 }
3753 const to = flip(last.to)
3754 if (to.encoding) {
3755 return replaceEncoding(to, [...to.encoding, ...ls])
3756 } else {
3757 return replaceEncoding(to, ls)
3758 }
3759}
3760
3761/**
3762 * Swaps the decode and encode directions of an AST's {@link Encoding} chain.

Callers 1

SchemaAST.tsFile · 0.85

Calls 3

replaceEncodingFunction · 0.85
flipFunction · 0.70
flipMethod · 0.45

Tested by

no test coverage detected