Documentation
¶
Overview ¶
Package example provides a generic utility for processing structured data using markdown-formatted tables as input and output. It is designed to simplify the testing and demonstration of functions that operate on tabular data by allowing easy input specification and result visualization.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Run ¶
Run executes a function f with input data from a markdown table and outputs the results as a markdown table.
The function f can accept either a single item or a slice/array of items as input (type T), and should return a single item or a slice/array of items as output (type U), along with an error.
Run performs the following steps: 1. Parses the input markdown table. 2. Processes the input data based on the type of T (single item or slice/array). 3. Executes the provided function f with the processed input. 4. Formats the results (type U) into a markdown table. 5. Prints the formatted output table.
This function uses reflection to handle various input and output types, making it flexible for different use cases. It can adapt to both individual items and slices/arrays, depending on the function signature provided.
If any errors occur during parsing, processing, or function execution, Run will print an error message and return without producing output.
Types ¶
type RunConfig ¶
type RunConfig struct {
// contains filtered or unexported fields
}
RunConfig holds configuration options for the Run function.
type RunOption ¶
type RunOption func(*RunConfig)
RunOption is a function type used to set options for the Run function.
func WithHeaderAliases ¶
WithHeaderAliases is a RunOption that sets up aliases for field names. This can be useful when the table headers don't exactly match the struct field names, allowing for more flexible parsing. In the aliases map, each key is an alias and its corresponding value is the struct field name it represents.
func WithOutputHeader ¶
WithOutputHeader sets the output headers using a markdown-formatted header row.
func WithOutputHeaders ¶
WithOutputHeaders sets the output headers using a slice of strings.
Directories
¶
Path | Synopsis |
---|---|
examples
|
|
calculator
Package calculator provides basic arithmetic operations on numeric data.
|
Package calculator provides basic arithmetic operations on numeric data. |