Lists - bali-nebula/go-component-framework GitHub Wiki
Overview
A list is a collection that preserves the order of the values as they are added and manipulated. Each value in a list is a component and a value may be added to a list more than once. The values in a list may be sorted into their natural ordering.
A Quick Example
To whet your appetite, here is some short example code that demonstrates the behavior of lists.
package main
import (
fmt "fmt"
bal "github.com/bali-nebula/go-component-framework/v2/bali"
)
func main() {
// Create a new list from a string containing Bali Document Notation™.
var list = bal.List(`[
"alpha"
"beta"
"gamma"
]`)
fmt.Println("The initial list:", bal.FormatEntity(list))
// Add some more values to the list.
list.AddValue(bal.Component(`"delta"`))
list.AddValue(bal.Component(`"epsilon"`))
fmt.Println("The augmented list:", bal.FormatEntity(list))
// Change a value in the list.
list.SetValue(2, bal.Component(`"zeta"`))
fmt.Println("The updated list:", bal.FormatEntity(list))
// Sort the values in the list.
list.SortValues()
fmt.Println("The sorted list:", bal.FormatEntity(list))
// Randomly shuffle the values in the list.
list.ShuffleValues()
fmt.Println("The shuffled list:", bal.FormatEntity(list))
// Remove a value from the list.
list.RemoveValue(4)
fmt.Println("The shortened list:", bal.FormatEntity(list))
// Remove all values from the list.
list.RemoveAll()
fmt.Println("The empty list:", bal.FormatEntity(list))
}