Documentation
¶
Index ¶
- func Filter[E any](sl []E, fn func(E) bool) []E
- func Index[E comparable](sl []E, v E) int
- func Insert[E any](sl []E, index int, item E) ([]E, error)
- func Move[E any](sl []E, from, to int) ([]E, error)
- func RealIndex[E any](sl []E, idx int, clampMax bool) (int, error)
- func Remove[E any](sl []E, index int) ([]E, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Filter ¶ added in v0.4.0
Filter returns a new slice with only the items that the given function returns true for.
func Index ¶ added in v0.4.0
func Index[E comparable](sl []E, v E) int
Index returns the first (lowest) index of the value within the given slice. If the value is not found, -1 is returned. slices is only in stdlib as of Go 1.21; need to have this for 1.20
func Insert ¶
Insert inserts the given item at the given index. If the index is larger than possible or -1, the item is inserted at the end of the list via append. All items at list.Items[index] are moved up by one to make room for the new item.
func Move ¶
Move moves the item at index from to index to. If from is out of bounds, an error is returned. If to is negative or greater than allowed index, the item is moved to the end of the list.
func RealIndex ¶
RealIndex returns the given index if it is valid. If the index is -1, it is converted to the highest valid index. If the index is greater than the highest valid, the behavior depends on clampMax; if clampMax is true, the index is converted to the highest valid index, and if clampMax is false, an error is returned. If a valid index is not possible, an error is returned. If the returned error is nil, the returned index is guaranteed to be able to be used in sl without panicking in its current state. Not thread-safe.
Even if an error is returned, the index at its last value is also returned, which informs what the actual index was at the time the error was discoverd.
Types ¶
This section is empty.