tree

package
v0.28.2 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2025 License: Apache-2.0 Imports: 2 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LeafPathPartsRenderFunc

type LeafPathPartsRenderFunc[T any] func(leaf T) []string

LeafPathPartsRenderFunc is a function that takes a leaf and returns a slice of strings. The strings are all the path parts from the root to the leaf. Each string is the rendered version of a path part.

func NewStringSplitRenderFunc

func NewStringSplitRenderFunc(sep string) LeafPathPartsRenderFunc[string]

NewStringSplitRenderFunc returns a LeafPathPartsRenderFunc that splits a string by the given separator.

For example, if you use a separator of "/", the render function will split the leaf string by "/" and return the resulting slice.

type Tree

type Tree[T any] struct {
	// contains filtered or unexported fields
}

func New

func New[T any](leaves []T, renderFunc LeafPathPartsRenderFunc[T]) (*Tree[T], error)

New returns a new Tree instance that's ready to be rendered.

It takes two parameters: leaves and renderFunc. The resulting tree will have one leaf per element in the leaves slice, and each leaf's ancestors are inferred from the slice returned by the renderFunc. When the tree is rendered, the renderFunc is called once per leaf, and it's expected to return a slice of strings, each of which are rendered versions of the leaf's ancestors and the leaf itself.

For example, let's say we use a leaves slice of []string{"ABC", "ABD", "BCD"} and a renderFunc implementation that returns a slice of the individual characters from the leaf string. The resulting tree would look like this:

	 A
	 └─ B
		  C
		  D
	 B
	 └─ C
          D

func (Tree[T]) Render

func (t Tree[T]) Render() string

Render returns a string rendering of the tree.

Jump to

Keyboard shortcuts

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