Source File
children.go
Belonging Package
charm.land/lipgloss/v2/tree
package treeimport// Children is the interface that wraps the basic methods of a tree model.type Children interface {// At returns the content item of the given index.At(index int) Node// Length returns the number of children in the tree.Length() int}// NodeChildren is the implementation of the Children interface with tree Nodes.type NodeChildren []Node// Append appends a child to the list of children.func ( NodeChildren) ( Node) NodeChildren {= append(, )return}// Remove removes a child from the list at the given index.func ( NodeChildren) ( int) NodeChildren {if < 0 || len() < +1 {return}= slices.Delete(, , +1)return}// Length returns the number of children in the list.func ( NodeChildren) () int {return len()}// At returns the child at the given index.func ( NodeChildren) ( int) Node {if >= 0 && < len() {return []}return nil}// NewStringData returns a Data of strings.func ( ...string) Children {:= make([]Node, 0, len())for , := range {:= Leaf{value: }= append(, &)}return NodeChildren()}var _ Children = NewFilter(nil)// Filter applies a filter on some data. You could use this to create a new// tree whose values all satisfy the condition provided in the Filter() function.type Filter struct {data Childrenfilter func(index int) bool}// NewFilter initializes a new Filter.func ( Children) *Filter {return &Filter{data: }}// At returns the item at the given index.// The index is relative to the filtered results.func ( *Filter) ( int) Node {:= 0for := range .data.Length() {if .filter() {if == {return .data.At()}++}}return nil}// Filter uses a filter function to set a condition that all the data must satisfy to be in the Tree.func ( *Filter) ( func( int) bool) *Filter {.filter =return}// Length returns the number of children in the tree.func ( *Filter) () int {:= 0for := range .data.Length() {if .filter() {++}}return}
The pages are generated with Golds v0.8.7. (GOOS=linux GOARCH=amd64)