Documentation
¶
Overview ¶
package Slice provides a custom Slice type with chainable methods with API similar to that of the standard library's slices package.
Index ¶
- type Slice
- func (self Slice[T]) All() iter.Seq2[int, T]
- func (self *Slice[T]) Append(elems ...T)
- func (self *Slice[T]) AppendSeq(seq iter.Seq[T])
- func (self Slice[T]) At(n int) T
- func (self Slice[T]) Backward() iter.Seq2[int, T]
- func (self Slice[T]) Clone() []T
- func (self *Slice[T]) Concat(elems []T)
- func (self Slice[T]) Contains(v T) bool
- func (self Slice[T]) ContainsFunc(f func(T) bool) bool
- func (self *Slice[T]) Delete(i, j int)
- func (self *Slice[T]) DeleteFunc(del func(T) bool)
- func (self Slice[T]) Equal(other Slice[T]) bool
- func (self Slice[T]) Index(v T) int
- func (self Slice[T]) IndexFunc(f func(T) bool) int
- func (self *Slice[T]) Insert(i int, v ...T)
- func (self Slice[T]) Length() int
- func (self Slice[T]) Map(fn func(T) any) Slice[any]
- func (self *Slice[T]) Push(elem T)
- func (self *Slice[T]) Reverse()
- func (self Slice[T]) Values() iter.Seq[T]
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Slice ¶
type Slice[T comparable] struct { Items []T }
type Slice is alias for custom Generic slice type
func MapTo ¶
func MapTo[T, U comparable](self Slice[T], fn func(T) U) Slice[U]
MapTo applies the given function to each element and returns a new Slice with the transformed elements of the specified type U. This is the type-safe version of [Map] method.
func (Slice[T]) All ¶
All returns an iterator over index-value pairs in the slice in the usual order.
func (*Slice[T]) Append ¶
func (self *Slice[T]) Append(elems ...T)
Append appends a new single element to end of self
func (Slice[T]) At ¶
At returns the element at nth index of self. This is provided as a helper method for convenience, one can directly use Slice{}.Items[n]
func (Slice[T]) Backward ¶
Backward returns an iterator over index-value pairs in the Slice, traversing it backward with descending indices.
func (Slice[T]) Clone ¶
func (self Slice[T]) Clone() []T
Items return the shallow copy of underlying slice
func (*Slice[T]) Concat ¶
func (self *Slice[T]) Concat(elems []T)
Concat appends every element in elems to end of self
func (Slice[T]) ContainsFunc ¶
ContainsFunc reports whether at least one element e of Slice satisfies f(e).
func (*Slice[T]) Delete ¶
Delete removes the elements self.Items[i:j] from self. Delete panics if j > self.Length() or self.Items[i:j] is not a valid slice of self. Delete is O(self.Length()-i), so if many items must be deleted, it is better to make a single call deleting them all together than to delete one at a time. Delete zeroes the elements self.Items[self.Length()-(j-i):self.Length()].
func (*Slice[T]) DeleteFunc ¶
DeleteFunc removes any elements from self for which del returns true. DeleteFunc zeroes the elements between the new length and the original length.
func (Slice[T]) Equal ¶
Equal reports whether two slices are equal: the same length and all elements equal. If the lengths are different, Equal returns false. Otherwise, the elements are compared in increasing index order, and the comparison stops at the first unequal pair. Empty and nil slices are considered equal. Floating point NaNs are not considered equal.
func (Slice[T]) Index ¶
Index returns the index of the first occurrence of v in self, or -1 if not present.
func (Slice[T]) IndexFunc ¶
IndexFunc returns the first index i satisfying f(self.At(i)), or -1 if none do.
func (*Slice[T]) Insert ¶
Insert inserts the values v... into self at index i. The elements at self.Items[i:] are shifted up to make room. In the modified Slice, self.At(i) == v[0], and, if i < self.Length(), self.At(i+len(v)) == value originally at self.At(i). Insert panics if i > self.Length(). This function is O(self.Length() + len(v)).
func (Slice[T]) Map ¶
Map applies the given function to each element and returns a new Slice with the transformed elements of type U
func (*Slice[T]) Push ¶
func (self *Slice[T]) Push(elem T)
Push inserts a single element to end of self