list

package
v0.0.0-...-7241100 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2019 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package list implements a persistent linked list.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type List

type List struct {
	// contains filtered or unexported fields
}

List is a persistent linked list.

func Cons

func Cons(elem interface{}, list *List) *List

Cons constructs a new list from the element and another list.

func Empty

func Empty() *List

Empty returns the empty list (nil).

func From

func From(value interface{}) *List

From will convert many go types to an immutable list. Converting some types is more efficient than others and the mechanisms are described below.

*List:

Returned directly as it is already immutable.

[]interface{}:

New is called with the elements.

seq.Sequable:

Seq is called on the value and the list is built from the resulting sequence. This will reverse the sequence.

seq.Sequence:

The list is built from the sequence. Care should be taken to provide finite sequences or the list will grow without bound. This will reverse the sequence.

[]T:

The slice is converted to a list using reflection.

func New

func New(elems ...interface{}) *List

New converts as list of elements to a persistent list.

func (*List) Conj

func (l *List) Conj(elem interface{}) interface{}

Conj constructs a new list from the element and another list. Conj implements a generic mechanism for building collections.

func (*List) Cons

func (l *List) Cons(elem interface{}) *List

Cons constructs a new list from the element and another list.

func (*List) Equal

func (l *List) Equal(other interface{}) bool

Equal returns whether the other value is a list, and all the values are equal to their corresponding partner in the other list.

func (*List) Find

func (l *List) Find(value interface{}) (interface{}, bool)

Find whether the value exists in the list by walking every value. Returns the value and whether or not it was found.

func (*List) First

func (l *List) First() interface{}

First returns the first element of a list.

func (*List) Length

func (l *List) Length() int

Length returns the number of members of the list

func (*List) Next

func (l *List) Next() *List

Next returns the next list in the chain.

func (*List) Range

func (l *List) Range(do interface{})

Range calls the passed in function on each element of the list. The function passed in may be of many types:

func(value interface{}) bool:

Takes a value of any type and returns if the loop should continue.
Useful to avoid reflection where not needed and to support
heterogenous lists.

func(value interface{})

Takes a value of any type.
Useful to avoid reflection where not needed and to support
heterogenous lists.

func(value T) bool:

Takes a value of the type of element stored in the list and
returns if the loop should continue. Useful for homogeneous lists.
Is called with reflection and will panic if the type is incorrect.

func(value T)

Takes a value of the type of element stored in the list and
returns if the loop should continue. Useful for homogeneous lists.
Is called with reflection and will panic if the type is incorrect.

Range will panic if passed anything that doesn't match one of these signatures

func (*List) Seq

func (l *List) Seq() seq.Sequence

Seq returns a representation of the list as a sequence corresponding to the elements of the list.

func (*List) String

func (l *List) String() string

String returns a string representation of the list.

Jump to

Keyboard shortcuts

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