Sets - bali-nebula/go-component-framework GitHub Wiki
Overview
A set is an ordered collection where each value is a component. The values are automatically sorted into their natural ordering. Each value in a set must be unique.
A Quick Example
To whet your appetite, here is some short example code that demonstrates the behavior of sets.
package main
import (
fmt "fmt"
bal "github.com/bali-nebula/go-component-framework/v2/bali"
)
func main() {
// Create a new set from a string containing Bali Document Notation™.
var set = bal.Set(`[
$red
$orange
$yellow
$green
$blue
$violet
]($type: /bali/types/collections/Set/v1)`)
fmt.Println("The initial set:", bal.FormatEntity(set))
// Add another value to the set (twice, only one will be added).
set.AddValue(bal.Component(`$indigo`))
set.AddValue(bal.Component(`$indigo`))
fmt.Println("The augmented set:", bal.FormatEntity(set))
// Remove a value from the set.
set.RemoveValue(bal.Component(`$yellow`))
fmt.Println("The shortened set:", bal.FormatEntity(set))
// Remove all values from the set.
set.RemoveAll()
fmt.Println("The empty set:", bal.FormatEntity(set))
}