operation

command
v0.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 31, 2025 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Operation generates the interfaces and glue-code for the visitor pattern. The visitor pattern is used in place of tagged-unions in this codebase since Go does not support that feature.

Instead of implementing a type switch which handles every type in the union, a visitor interface is implemented with methods handling each type. The correct method is called at runtime via some generated glue code. This glue code also defines an interface for the union itself, allowing us to avoid using interface{}.

Structs implementing these visitor interfaces define a parameterized (generic) function for the types in the union. For this reason, they are called "operations" rather than "visitors" in this codebase.

Usage:

//go:generate go run ./operation [flags]

Flags:

-op-name string      the name of the interface of the visitor
-param-name string   the name of the interface being visited
-types string        a comma-separated list of concrete types to visit

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL