orderedlist

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2025 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package orderedlist defines the OrderedList struct, an implementation of the OrderedCollection interface, and supporting functions. An OrderedList is a collection of constraints.Ordered items maintained in their constraints.Ordered order.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Map

func Map[S cmp.Ordered, T cmp.Ordered](
	mapper result.FlatMapper[S, T],
	source *OrderedList[S],
) result.Result[*OrderedList[T]]

Map the given OrderedList using the given mapper and filter, returning an OrderedList of mapped items, never nil; an error is returned if either the mapper or the filter fails.

Types

type OrderedList

type OrderedList[T cmp.Ordered] struct {
	*list.List[T]
	// contains filtered or unexported fields
}

OrderedList defines the structure of an ordered list collection, an implementation of the collections.OrderedCollection interface. A List is a slice of constraint.Ordered items; duplicates are allowed. This type is not thread-safe.

func New

func New[T cmp.Ordered](size int) *OrderedList[T]

New creates a OrderedList of the given size.

func NewFrom

func NewFrom[T cmp.Ordered](items ...T) *OrderedList[T]

NewFrom creates a OrderedList containing the given items.

func NewFromCollection

func NewFromCollection[T cmp.Ordered](source collections.Collection[T]) *OrderedList[T]

NewFromCollection creates a OrderedList containing the items in the given Collection.

func NewWithAccessor

func NewWithAccessor[T cmp.Ordered](size int) (*OrderedList[T], func() []T)

NewWithAccessor creates a OrderedList of the given size, along with an accessor function. The accessor function is intended for use by composite types that need direct access to the OrderedList's implementation; the accessor function should not be shared.

func (*OrderedList[T]) Add

func (odrList *OrderedList[T]) Add(item ...T) collections.Collection[T]

Add the given items to the receiver. Returns the receiver as a collections.Collection.

func (*OrderedList[T]) Contains

func (odrList *OrderedList[T]) Contains(item T) bool

Contains returns true if the given item is contained in the receiver, otherwise false.

func (*OrderedList[T]) Detect

func (odrList *OrderedList[T]) Detect(filter filters.Filter[T]) result.Result[maybe.Maybe[T]]

Detect queries the receiver for an item matching the given filter. Returns the detected item, and true when found, otherwise the zero value and false; an error is returned if the filter fails.

func (*OrderedList[T]) First

func (odrList *OrderedList[T]) First() result.Result[T]

First returns the first item in the receiver; an error is returned if the receiver is empty.

func (*OrderedList[T]) Get

func (odrList *OrderedList[T]) Get(index int) result.Result[T]

Get returns the item in the receiver at the given index; an error is returned if the index is invalid.

func (*OrderedList[T]) Index

func (odrList *OrderedList[T]) Index(item T) int

Index returns the index of the given item in the receiver, or -1 if the given item is not contained in the receiver.

func (*OrderedList[T]) Insert

func (odrList *OrderedList[T]) Insert(index int, item T) error

Insert at the given index the given item. Returns an error if index is out of bounds.

func (*OrderedList[T]) Largest

func (odrList *OrderedList[T]) Largest() result.Result[T]

Largest returns the lexicographical largest item contained in the receiver.

func (*OrderedList[T]) Last

func (odrList *OrderedList[T]) Last() result.Result[T]

Last returns the last item in the receiver; an error is returned if the receiver is empty.

func (*OrderedList[T]) Len

func (odrList *OrderedList[T]) Len() int

Len returns the length of the receiver; an empty receiver has a length of zero.

func (*OrderedList[T]) Remove

func (odrList *OrderedList[T]) Remove(item T) collections.Collection[T]

Remove the given item from the receiver. If the item does not exist the receiver is unchanged.Returns the receiver as a collections.Collection.

func (*OrderedList[T]) Select

func (odrList *OrderedList[T]) Select(filter filters.Filter[T]) result.Result[collections.Collection[T]]

Select returns the receiver's items that match the given filter; an error is returned if the filter fails. The returned collection is the same species as the receiver, and never nil.

func (*OrderedList[T]) Set

func (odrList *OrderedList[T]) Set(index int, item T) result.Result[T]

Set the given item at the given index in the receiver, returning the item that previously occupied the given index, or the zero value, if the index is previously unoccupied; an error is returned if the index is invalid.

func (*OrderedList[T]) Smallest

func (odrList *OrderedList[T]) Smallest() result.Result[T]

Smallest returns the lexicographical smallest item contained in the receiver; additional, an error is returned if the receiver is empty.

func (*OrderedList[T]) SortAscending

func (odrList *OrderedList[T]) SortAscending() collections.OrderedCollection[T]

SortAscending sorts the content of the receiver in ascending lexical order.

func (*OrderedList[T]) SortDescending

func (odrList *OrderedList[T]) SortDescending() collections.OrderedCollection[T]

SortDescending sorts the content of the receiver in descending lexical order.

func (*OrderedList[T]) String

func (odrList *OrderedList[T]) String() string

String returns a human-readable representation of the receiver.

func (*OrderedList[T]) ToCollection

func (odrList *OrderedList[T]) ToCollection() collections.Collection[T]

ToCollection returns the receiver as a collections.Collection.

func (*OrderedList[T]) ToOrderedCollection

func (odrList *OrderedList[T]) ToOrderedCollection() collections.OrderedCollection[T]

ToOrderedCollection returns the receiver as a collections.OrderedCollection.

func (*OrderedList[T]) ToSlice

func (odrList *OrderedList[T]) ToSlice() []T

ToSlice returns a new slice of items contained in the receiver. Changes to the slice do not affect the contents of the receiver.

Jump to

Keyboard shortcuts

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