Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type LeafPathPartsRenderFunc ¶
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