Lists - craterdog/go-component-framework GitHub Wiki

Overview

A list is a collection that preserves the order of the values as they are added and manipulated. Lists can be sorted by value using either the default (natural) ranking function or a custom ranking function that is passed into the sort request.

UML Diagram

A Quick Example

To whet your appetite, here is some short example code that demonstrates the use of lists.

package main

import (
	fmt "fmt"
	fra "github.com/craterdog/go-component-framework/v7"
)

func main() {
	// Create a new list from an array using the module constructor shortcut.
	var list = fra.ListFromArray[string](
		[]string{"Monday", "Wednesday", "Friday"},
	)
	fmt.Println(list)

	// Append a value to the list.
	list.AppendValue("Saturday")
	fmt.Println(list)

	// Insert a value at the beginning of the list (slot 0).
	list.InsertValue(0, "Sunday")
	fmt.Println(list)

	// Insert values inside the list in slots 2 and 4.
	list.InsertValue(2, "Tuesday")
	list.InsertValue(4, "Thursday")
	fmt.Println(list)

	// Replace a value in the list.
	list.SetValue(2, "Montag")
	fmt.Println(list)
}

Try it out in the Go Playground...