Documentation ¶
Overview ¶
Package list implements a persistent linked list.
Index ¶
- type List
- func (l *List) Conj(elem interface{}) interface{}
- func (l *List) Cons(elem interface{}) *List
- func (l *List) Equal(other interface{}) bool
- func (l *List) Find(value interface{}) (interface{}, bool)
- func (l *List) First() interface{}
- func (l *List) Length() int
- func (l *List) Next() *List
- func (l *List) Range(do interface{})
- func (l *List) Seq() seq.Sequence
- func (l *List) String() string
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 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) Equal ¶
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 ¶
Find whether the value exists in the list by walking every value. Returns the value and whether or not it was found.
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