Skip to content

aruuunn/immutablelist

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

13 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ”— Immutable List

GoDoc Go

A small go package which implements Immutable List (Persistent Data Structure).

Read about Persistent Data Structures at wikipedia.

Installation

go get github.com/arunmurugan78/immutablelist 

Quick Start

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(🍷, πŸ•, 🍺, πŸ—, πŸ”)
}

About

A small go package which implements Immutable List (Persistent Data Structure).

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages