Skip to content

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

Notifications You must be signed in to change notification settings

ArunMurugan78/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