Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewStackIsEmptyNativeError ¶
func NewStackIsEmptyNativeError() error
NewStackIsEmptyNativeError creates an untranslated error to indicate stack is empty (internal error)
Types ¶
type Iterator ¶ added in v0.4.0
type Iterator[T any] interface { IteratorCtrl[T] // Start returns the first element of the sequence and moves the current // position to the next item. Start() T // Next moves the iterator to the next item in the sequence then returns // that item. If the iterator is already at the end, then the zero // value of T is returned. However, when used properly, this situation // should never occur, as Valid would indicate that iteration with // Next should no longer occur. Next() T // Reset is designed to be used in high frequency applications. The client // can reuse this iterator for a new collection rather that having to throw this // instance away and create a new one. This helps to reduce the number of // allocations in a high frequency application. Reset(entries []T) }
Iterator represents an iterator over a slice. The underlying slice may be empty. When created, the iterator does not point to a valid slice entry. To begin iteration, the client invokes Start. At any stage after the iteration has started, the iterator, points to the current item in the sequence. The client can query the validity of the current item using the Valid method. To obtain successive elements, the client invokes the Next method and this can be continued until Valid returns false. Once Valid returns false, the client should no longer call Next. Doing so in this scenario, returns the zero value for the value T. It should also be noted that the iterator does not in itself implement the loop operation, it merely provides the logic to enable the client to implement the looping operation.
func ForwardIt ¶ added in v0.5.0
ForwardIt creates a forward iterator over a non empty slice. If the provided slice is empty, then a nil iterator is returned.
The zero value represents the value that is returned if the Next method on the iterator is incorrectly invoked after Valid has returned false. If the collection contains interfaces, or pointers just pass in nil as the zero value.
If the collection contains scalars, pass in 0 cast to the appropriate type, eg int32(0). It doesn't matter if 0 is a valid value in the collection, because this value is only ever return in an invalid scenario, ie, calling Next after Valid has returned false. This is preferable than generating a panic. If the collection contains structs, then pass in an empty struct as the nil value.
type IteratorCtrl ¶ added in v0.4.0
IteratorCtrl represents a narrow view of the iterator that exposes just the method, Valid which indicates when all items in the sequence have been consumed. The purpose of this is to allow a client abstraction, which implements the looping logic to provide a condition which halts its iteration. There are 2 scenarios: 1) the client wants to iterate the entire sequence; in this case the client just needs to continue the iteration until Valid returns false. 2) the client only wants to iterate the sequence until a certain other condition arises; in this case, the client combines the result of Valid() with another predicate within the for statement.
type OrderedKeysMap ¶ added in v0.4.0
OrderedKeysMap provides a deterministic way to iterate the contents of a map. The problem with a regular iteration is that the order the elements are presented is not guaranteed. This can be detrimental when consistency is paramount. Any map that needs to be iterated deterministically, should use the Keys() function for the iteration loop and obtain the value using this key to index into the map.
func (*OrderedKeysMap[K, V]) Keys ¶ added in v0.4.0
func (m *OrderedKeysMap[K, V]) Keys() []K
type RunEach ¶ added in v0.5.0
RunEach is a client defined function which is invoked for each element in the sequence.
type RunWhile ¶ added in v0.5.0
RunWhile is a client defined function that denotes that the iteration can continue. When it returns false, iteration lapses.
type RunnableIterator ¶ added in v0.5.0
type RunnableIterator[T any, R any] interface { Iterator[T] // RunAll invokes the predicate for every member of the sequence, while // Valid and while both holds true. RunAll(each RunEach[T, R], while RunWhile[T, R]) }
RunnableIterator implements a looping mechanism for the Iterator. The runnable version is intended to make iteration just that little bit easier. The key feature of the runnable iterator is to be able to process a sequence while a certain condition holds true (defined, by the client using the while function.) The runnable iterator passes the return value for that particular item, to the while function, along with the item itself, so that it can define logic based on the return result. If the client always want to invoke all items in a sequence, then the better solution would be just to use a standard for/range statement, rather than use this iterator.
func ForwardRunIt ¶ added in v0.5.0
ForwardRunIt creates a forward runnable iterator
func ReverseRunIt ¶ added in v0.5.0
ReverseRunIt creates a reverse runnable iterator
type Stack ¶
type Stack[T any] struct { // contains filtered or unexported fields }
Stack