A small go package which implements Immutable List (Persistent Data Structure).
Read about Persistent Data Structures at wikipedia.
go get github.com/arunmurugan78/immutablelist package main
import (
"fmt"
"github.com/arunmurugan78/immutablelist"
)
func main() {
list := immutablelist.New()
list = list.Add("π") // Each operation returns a new list
list = list.Add("π") // Add adds the new item to the last of the list
list = list.Add("π")
list = list.Prepend("π·") // Prepend adds item to the start of list
fmt.Println(list) // Output ImmutableList(π·, π, π, π)
// Best way to iterate through the list
for item := range list.Iterator() {
fmt.Printf("list item: %v\n", item)
}
fmt.Println(list.DeleteAt(1)) // ImmutableList(π·, π, π)
fmt.Println("Length", list.Size()) // Length 4
fmt.Println(list.InsertAt(2, "πΊ")) // ImmutableList(π·, π, πΊ, π, π)
}