Documentation ¶
Overview ¶
Package list implements support for a generic ordered List. A List is a Collection that wraps an underlying doubly linked list and provides convenience methods and syntatic sugar on top of it.
Compared to a Sequence, a List allows for efficient insertion and removal of elements at the edges of the list, but slower access to arbitrary elements. This makes the List a good choice for implementing queues or stacks.
For a list of comparable types, consider using ComparableList, which provides additional methods for comparable types.
Index ¶
- type ComparableList
- func (l *ComparableList[T]) Contains(v T) bool
- func (l *ComparableList[T]) Diff(s *ComparableList[T]) *ComparableList[T]
- func (l *ComparableList[T]) Distinct() *ComparableList[T]
- func (l *ComparableList[T]) Equals(s *ComparableList[T]) bool
- func (l *ComparableList[T]) Exists(v T) bool
- func (l *ComparableList[T]) IndexOf(v T) int
- func (l *ComparableList[T]) LastIndexOf(v T) int
- func (l *ComparableList[T]) Max() (T, error)
- func (l *ComparableList[T]) Min() (T, error)
- func (c *ComparableList[T]) New(s ...[]T) collection.Collection[T]
- func (c *ComparableList[T]) NewOrdered(s ...[]T) collection.OrderedCollection[T]
- func (l *ComparableList[T]) Sum() T
- type List
- func (l *List[T]) Add(v T)
- func (l *List[T]) All() iter.Seq2[int, T]
- func (l *List[T]) Apply(f func(T) T) *List[T]
- func (l *List[T]) At(index int) T
- func (l *List[T]) Backward() iter.Seq2[int, T]
- func (l *List[T]) Clone() *List[T]
- func (l *List[T]) Concat(lists ...*List[T]) *List[T]
- func (l *List[T]) Contains(f func(T) bool) bool
- func (l *List[T]) Corresponds(s *List[T], f func(T, T) bool) bool
- func (l *List[T]) Count(f func(T) bool) int
- func (l *List[T]) Dequeue() (T, error)
- func (l *List[T]) Distinct(f func(T, T) bool) *List[T]
- func (l *List[T]) Drop(n int) *List[T]
- func (l *List[T]) DropRight(n int) *List[T]
- func (l *List[T]) DropWhile(f func(T) bool) *List[T]
- func (l *List[T]) Enqueue(v T)
- func (l *List[T]) Equals(s *List[T], f func(T, T) bool) bool
- func (l *List[T]) Exists(f func(T) bool) bool
- func (l *List[T]) Filter(f func(T) bool) *List[T]
- func (l *List[T]) FilterNot(f func(T) bool) *List[T]
- func (l *List[T]) Find(f func(T) bool) (int, T)
- func (l *List[T]) FindLast(f func(T) bool) (int, T)
- func (l *List[T]) ForAll(f func(T) bool) bool
- func (l *List[T]) Head() (T, error)
- func (l *List[T]) Init() *List[T]
- func (l *List[T]) IsEmpty() bool
- func (l *List[T]) Last() (T, error)
- func (l *List[T]) Length() int
- func (l *List[T]) New(s ...[]T) collection.Collection[T]
- func (l *List[T]) NewOrdered(s ...[]T) collection.OrderedCollection[T]
- func (l *List[T]) NonEmpty() bool
- func (l *List[T]) Partition(f func(T) bool) (*List[T], *List[T])
- func (l *List[T]) Pop() (T, error)
- func (l *List[T]) Push(v T)
- func (l *List[T]) Random() T
- func (l *List[T]) Reverse() *List[T]
- func (l *List[T]) Slice(start, end int) collection.OrderedCollection[T]
- func (l *List[T]) SplitAt(n int) (*List[T], *List[T])
- func (l *List[T]) String() string
- func (l *List[T]) Tail() *List[T]
- func (l *List[T]) Take(n int) *List[T]
- func (l *List[T]) TakeRight(n int) *List[T]
- func (l *List[T]) ToSlice() []T
- func (l *List[T]) Values() iter.Seq[T]
- type Node
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ComparableList ¶
ComparableList is a list of comparable types. it is similar to List, but with additional methods that do not require a higher order function comparator to be provided as an argument: Max(), Min(), Sum(), Distinct(), Diff(c), and Exists(v).
func NewComparableList ¶
func NewComparableList[T cmp.Ordered](s ...[]T) *ComparableList[T]
func (*ComparableList[T]) Contains ¶
func (l *ComparableList[T]) Contains(v T) bool
Contains returns true if the list contains the given value.
func (*ComparableList[T]) Diff ¶
func (l *ComparableList[T]) Diff(s *ComparableList[T]) *ComparableList[T]
Diff returns a new list containing the elements of the original list that are not in the other list.
func (*ComparableList[T]) Distinct ¶
func (l *ComparableList[T]) Distinct() *ComparableList[T]
Distinct returns a new list containing only the unique elements from the original list.
func (*ComparableList[T]) Equals ¶
func (l *ComparableList[T]) Equals(s *ComparableList[T]) bool
Equals returns true if the two lists are equal.
func (*ComparableList[T]) Exists ¶
func (l *ComparableList[T]) Exists(v T) bool
Exists is an alias for Contains
func (*ComparableList[T]) IndexOf ¶
func (l *ComparableList[T]) IndexOf(v T) int
IndexOf returns the index of the first occurrence of the specified element in this list,
func (*ComparableList[T]) LastIndexOf ¶
func (l *ComparableList[T]) LastIndexOf(v T) int
LastIndexOf returns the index of the last occurrence of the specified element in this list,
func (*ComparableList[T]) Max ¶
func (l *ComparableList[T]) Max() (T, error)
Max returns the maximum element in the list.
func (*ComparableList[T]) Min ¶
func (l *ComparableList[T]) Min() (T, error)
Min returns the minimum element in the list.
func (*ComparableList[T]) New ¶
func (c *ComparableList[T]) New(s ...[]T) collection.Collection[T]
func (*ComparableList[T]) NewOrdered ¶
func (c *ComparableList[T]) NewOrdered(s ...[]T) collection.OrderedCollection[T]
func (*ComparableList[T]) Sum ¶
func (l *ComparableList[T]) Sum() T
Sum returns the sum of the elements in the list.
type List ¶
type List[T any] struct { // contains filtered or unexported fields }
func (*List[T]) Backward ¶
Backward returns an index/value iterator for all nodes in the list in reverse order.
func (*List[T]) Contains ¶
Contains tests whether a predicate holds for at least one element of this list.
func (*List[T]) Corresponds ¶
Corresponds is an alias for collection.Corresponds
func (*List[T]) Distinct ¶
Distinct takes an "equality" function as an argument such as func(a T, b T) bool {return a == b} and returns a new sequence containing all the unique elements. If you don't want to pass an equality function use a ComparableList.
func (*List[T]) Equals ¶
Equals takes a list and an equality function as arguments and returns true if the two sequences are equal. If you prefer not to pass an equality function use a ComparableList.
func (*List[T]) New ¶
func (l *List[T]) New(s ...[]T) collection.Collection[T]
New returns a new list.
func (*List[T]) NewOrdered ¶
func (l *List[T]) NewOrdered(s ...[]T) collection.OrderedCollection[T]
NewOrdered returns a new ordered collection.
func (*List[T]) Slice ¶
func (l *List[T]) Slice(start, end int) collection.OrderedCollection[T]
Slice returns a new list containing only the nodes between the start and end indices.