Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type List ¶
type List[T any] interface { // Returns the length of the underlying slice Len() int /* Returns the index given a predicate that is called for each value in the list. The predicate function should return true for the value you want. This avoid strict == checks that would only work for native data types. index := list.Index(func(val int) bool { return val == 20 }) Big O(n) in worst-case scenario. */ Index(cmp func(val T) bool) int /* Append elements into the list. Append will resize the underlying slice if necessary. */ Append(vals ...T) /* Insert inserts a value at index in the under lying slice. index should not be out-of-bounds, otherwise this method will panic. */ Insert(index int, val T) // At returns element at the given index // Does not do out-of-bounds check on the index and will panic if index // is not valid. Get(index int) T /* Creates a slice expression from start to end and wraps it in a new List. Constraints: - start and end must be in the range capacity of list(inclusive) - start <= end */ Slice(start int, end int) List[T] /*copies this list into a new list of the same length and capacity*/ Clone() List[T] /*Removes the item at index. index should be within bounds otherwise this method will panic out-of-bounds. Remove if successful will change the length of the underling slice. */ Remove(index int) // ForEach iterates and passes the index and value to the callback. ForEach(callback func(index int, val T)) // given a callback, ForEach iterates and passes the index and pointer to value to the callback. ForEachPtr(callback func(index int, val *T)) // Filter items in list given a predicate. // Filter does not mutate the underlying array. Filter(predicate func(val T) bool) List[T] }
golang generic slice data structure.
func New ¶
Takes the same arguments as make, except that if no size is provided, the undelying slice is not pre-allocated.
func NewListFromSlice ¶
Click to show internal directories.
Click to hide internal directories.