list

package
v1.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 9, 2015 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Package list provides list implementations. Currently, this includes a persistent, immutable linked list.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type PersistentList

type PersistentList interface {
	// Head returns the head of the list. The bool will be false if the list is
	// empty.
	Head() (interface{}, bool)

	// Tail returns the tail of the list. The bool will be false if the list is
	// empty.
	Tail() (PersistentList, bool)

	// IsEmpty indicates if the list is empty.
	IsEmpty() bool

	// Length returns the number of items in the list.
	Length() uint

	// Add will add the item to the list, returning the new list.
	Add(head interface{}) PersistentList

	// Insert will insert the item at the given position, returning the new
	// list or an error if the position is invalid.
	Insert(val interface{}, pos uint) (PersistentList, error)

	// Get returns the item at the given position or an error if the position
	// is invalid.
	Get(pos uint) (interface{}, bool)

	// Remove will remove the item at the given position, returning the new
	// list or an error if the position is invalid.
	Remove(pos uint) (PersistentList, error)

	// Find applies the predicate function to the list and returns the first
	// item which matches.
	Find(func(interface{}) bool) (interface{}, bool)

	// FindIndex applies the predicate function to the list and returns the
	// index of the first item which matches or -1 if there is no match.
	FindIndex(func(interface{}) bool) int

	// Map applies the function to each entry in the list and returns the
	// resulting slice.
	Map(func(interface{}) interface{}) []interface{}
}

PersistentList is an immutable, persistent linked list.

var (
	// Empty is an empty PersistentList.
	Empty PersistentList = &emptyList{}

	// ErrEmptyList is returned when an invalid operation is performed on an
	// empty list.
	ErrEmptyList = errors.New("Empty list")
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL