list

package
v0.0.0-...-dcba59a Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ListSerializer

type ListSerializer[T cmp.Ordered] interface {
	Serialize(writer io.Writer, vertices []*dag.Vertex[T]) error
}

ListSerializer is an interface that defines a method to create a serializable object from a vertex.

type ListSerializerFunc

type ListSerializerFunc[T cmp.Ordered] func(writer io.Writer, vertices []*dag.Vertex[T]) error

ListSerializerFunc is a function type that implements the ListSerializer interface.

func (ListSerializerFunc[T]) Serialize

func (f ListSerializerFunc[T]) Serialize(writer io.Writer, vertices []*dag.Vertex[T]) error

Serialize implements the ListSerializer interface for ListSerializerFunc.

type Renderer

type Renderer[T cmp.Ordered] struct {
	// contains filtered or unexported fields
}

Renderer renders a tree from a DirectedAcyclicGraph as a flat last in a particular output format. The output rendered by the Renderer with OutputFormatJSON looks like this:

[
  "A",
  "B",
  "C",
  "D"
]

The output is analogous to a tree structure, but without the indentation.

── A
   ├─ B
   │  ╰─ C
   ╰─ D

Each letter corresponds to a vertex in the DirectedAcyclicGraph. The concrete representation of the vertex is defined by the ListSerializer.

func New

func New[T cmp.Ordered](ctx context.Context, graph *syncdag.SyncedDirectedAcyclicGraph[T], opts ...RendererOption[T]) *Renderer[T]

New creates a new Renderer for the given DirectedAcyclicGraph.

func (*Renderer[T]) Render

func (r *Renderer[T]) Render(ctx context.Context, writer io.Writer) error

Render renders the tree structure starting from the root ID. It writes the output to the provided writer.

type RendererOption

type RendererOption[T cmp.Ordered] func(*RendererOptions[T])

RendererOption is a function that modifies the RendererOptions.

func WithListSerializer

func WithListSerializer[T cmp.Ordered](serializer ListSerializer[T]) RendererOption[T]

WithListSerializer sets the ListSerializer for the Renderer.

func WithListSerializerFunc

func WithListSerializerFunc[T cmp.Ordered](serializerFunc func(writer io.Writer, vertices []*dag.Vertex[T]) error) RendererOption[T]

WithListSerializerFunc sets the ListSerializer based on a function.

func WithRoots

func WithRoots[T cmp.Ordered](roots ...T) RendererOption[T]

WithRoots sets the roots for the Renderer.

type RendererOptions

type RendererOptions[T cmp.Ordered] struct {
	// The ListSerializer converts a vertex to an object that is expected to
	// be a serializable type (e.g., a struct or map). The ListSerializer MUST
	// perform READ-ONLY access to the vertex and its attributes.
	ListSerializer ListSerializer[T]
	// Roots are the root vertices of the list to render.
	Roots []T
}

RendererOptions defines the options for the list Renderer.

type Serializer

type Serializer[T cmp.Ordered] struct {
	// VertexSerializer is a function that converts a vertex to an object
	// that can be serialized to JSON.
	VertexSerializer VertexSerializer[T]
	// OutputFormat specifies the format in which the output should be rendered.
	// Serializer supports JSON, NDJSON, and YAML formats.
	OutputFormat render.OutputFormat
}

Serializer implements the ListSerializer interface for serializing a slice of vertices to a set of output formats.

func NewSerializer

func NewSerializer[T cmp.Ordered](opts ...SerializerOption[T]) Serializer[T]

func (Serializer[T]) Serialize

func (s Serializer[T]) Serialize(writer io.Writer, vertices []*dag.Vertex[T]) error

type SerializerOption

type SerializerOption[T cmp.Ordered] func(*Serializer[T])

SerializerOption is a function that modifies the SerializerOptions.

func WithOutputFormat

func WithOutputFormat[T cmp.Ordered](format render.OutputFormat) SerializerOption[T]

WithOutputFormat sets the output format for the Serializer.

func WithVertexSerializer

func WithVertexSerializer[T cmp.Ordered](serializer VertexSerializer[T]) SerializerOption[T]

WithVertexSerializer sets the VertexSerializer for the Renderer.

func WithVertexSerializerFunc

func WithVertexSerializerFunc[T cmp.Ordered](serializerFunc func(vertex *dag.Vertex[T]) (any, error)) SerializerOption[T]

WithVertexSerializerFunc sets the VertexSerializer based on a function.

type VertexSerializer

type VertexSerializer[T cmp.Ordered] interface {
	// Serialize converts a vertex to an object that can be serialized.
	Serialize(vertex *dag.Vertex[T]) (any, error)
}

type VertexSerializerFunc

type VertexSerializerFunc[T cmp.Ordered] func(vertex *dag.Vertex[T]) (any, error)

VertexSerializerFunc is a function type that implements the VertexSerializer interface.

func (VertexSerializerFunc[T]) Serialize

func (f VertexSerializerFunc[T]) Serialize(vertex *dag.Vertex[T]) (any, error)

Jump to

Keyboard shortcuts

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