Documentation
¶
Index ¶
- type Element
- type Iterator
- type List
- func (l *List[T]) Back() *Element[T]
- func (l *List[T]) Copy() *List[T]
- func (l *List[T]) EltAtIndex(idx int) *Element[T]
- func (l *List[T]) Front() *Element[T]
- func (l *List[T]) Init() *List[T]
- func (l *List[T]) InsertAfter(v T, mark *Element[T]) *Element[T]
- func (l *List[T]) InsertBefore(v T, mark *Element[T]) *Element[T]
- func (l *List[T]) Iter() iter.Seq[T]
- func (l *List[T]) Iterator() Iterator[T]
- func (l *List[T]) Len() int
- func (l *List[T]) MoveAfter(e, mark *Element[T])
- func (l *List[T]) MoveBefore(e, mark *Element[T])
- func (l *List[T]) MoveToBack(e *Element[T])
- func (l *List[T]) MoveToFront(e *Element[T])
- func (l *List[T]) PopBack() T
- func (l *List[T]) PopFront() T
- func (l *List[T]) PushBack(v T) *Element[T]
- func (l *List[T]) PushBackList(other *List[T])
- func (l *List[T]) PushFront(v T) *Element[T]
- func (l *List[T]) PushFrontList(other *List[T])
- func (l *List[T]) Remove(e *Element[T]) T
- func (l *List[T]) ToSlice() []T
- func (l *List[T]) ValueAtIndex(idx int) T
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Element ¶
type Element[T any] struct { // contains filtered or unexported fields }
Element is a typed wrapper around list.Element
type Iterator ¶
type Iterator[T any] interface { // ForEachRemaining calls a given function for each of the remaining elements ForEachRemaining(func(T)) // HasNext returns true if there is an element to read from using Next HasNext() bool // Next returns the current element and proceeds the iterator to the next element Next() T // Remove removes the last returned element from the underlying list. Example: // // iter := MakeList(1, 2, 3).Iterator() // for iter.HasNext() { // if iter.Next() == 2 { // iter.Remove() // } // } // // leaves [1,3] Remove() }
Iterator (deprecated) sets ground for a Java-Style iterator for lists. permit iteration.
Example:
iter := MakeList(1,2,3).Iterator()
for iter.HasNext() {
fmt.Print(iter.Next())
}
type List ¶
type List[T any] struct { // contains filtered or unexported fields }
List is a typed wrapper around list.List
func (*List[T]) EltAtIndex ¶ added in v2.0.3
EltAtIndex returns the element of a list at some index idx (or panics, if the list is too short). The first element has index 0.
Example
MakeList("a","b","c").EltAtIndex(1).Value()
Returns "b".
func (*List[T]) InsertAfter ¶
InsertAfter inserts a new element with value v to a list after the element mark
func (*List[T]) InsertBefore ¶
InsertAfter inserts a new element with value v to a list before the element mark
func (*List[T]) Iter ¶ added in v2.0.3
Iter returns an iterator for the list. Example:
lst := MakeList("a", "b")
for i := range lst.Iter() {
fmt.Println(i)
}
will print the strings "a" and "b".
func (*List[T]) Iterator ¶
Iterator creates a Java style iterator for the given list. It should be used like:
iter := MakeList(1,2,3).Iterator()
for iter.HasNext() {
fmt.Print(iter.Next())
}
func (*List[T]) MoveAfter ¶
MoveAfter moves a given element e after another element mark. e and mark must not be nil.
func (*List[T]) MoveBefore ¶
MoveBefore moves a given element e before another element mark. e and mark must not be nil.
func (*List[T]) MoveToBack ¶
MoveToBack moves e to the back of the list. If e is not an element of the list, nothing is changed
func (*List[T]) MoveToFront ¶
MoveToBack moves e to the front of the list. If e is not an element of the list, nothing is changed
func (*List[T]) PopBack ¶
func (l *List[T]) PopBack() T
PopBack Removes the last element of a list and returns its value. The list must not be empty.
func (*List[T]) PopFront ¶
func (l *List[T]) PopFront() T
PopFront Removes the first element of a list and returns its value. The list must not be empty.
func (*List[T]) PushBack ¶
PushBack creates a new element with value v at the end of the list and returns it.
func (*List[T]) PushBackList ¶
PushBackList appends values of another list to a given list. The other list is not changed.
func (*List[T]) PushFront ¶
PushFront creates a new element with value v at the start of the list and returns it.
func (*List[T]) PushFrontList ¶
PushFrontList puts values of another list to the front of a given list. The other list is not changed. The other list must not be nil.
func (*List[T]) ToSlice ¶
func (l *List[T]) ToSlice() []T
ToSlice returns a slice of the values of the elements of a list.
func (*List[T]) ValueAtIndex ¶ added in v2.0.4
ValueAtIndex returns the value of the element of a list at some index idx (or panics, if the list is too short). The first element has index 0.
Example
MakeList("a","b","c").ValueAtIndex(1)
Returns "b".