Hyperlinkv0.8.0-beta.28

SchemaAST

SchemaAST.flipconsteffect/SchemaAST.ts:3477
(ast: AST): AST

Swaps the decode and encode directions of an AST's Encoding chain.

Details

After flipping, what was decoding becomes encoding and vice versa. This is the core operation behind Schema.encode — encoding a value is decoding with a flipped SchemaAST.

  • Memoized: same input reference → same output reference.
  • Recursively walks composite nodes.
export const flip = memoize((ast: AST): AST => {
  if (ast.encoding) {
    return flipEncoding(ast, ast.encoding)
  }
  const out: any = ast
  return out.flip?.(flip) ?? out.recur?.(flip) ?? out
})
Referenced by 3 symbols