Documentation ¶
Overview ¶
Package types provides a generic data types similar to that of Ruby
Index ¶
- type Map
- func (m *Map[K, V]) Delete(k K)
- func (m *Map[K, V]) Load(k K) (v V, ok bool)
- func (m *Map[K, V]) LoadAndDelete(k K) (v V, loaded bool)
- func (m *Map[K, V]) LoadOrStore(k K, v V) (actual V, loaded bool)
- func (m *Map[K, V]) Range(f func(k K, v V) bool)
- func (m *Map[K, V]) Store(k K, v V)
- func (m *Map[K, V]) Swap(k K, v V) (previous V, loaded bool)
- type Slice
- func (a Slice[T]) All(block func(T) bool) bool
- func (a Slice[T]) Any(block func(T) bool) bool
- func (a Slice[T]) At(index int) *T
- func (a Slice[T]) CountBy(block func(T) bool) (count int)
- func (a Slice[T]) CountElement(element T) (count int)
- func (a Slice[T]) Cycle(count int, block func(T))
- func (a Slice[T]) Delete(element T) Slice[T]
- func (a Slice[T]) DeleteAt(index int) Slice[T]
- func (a Slice[T]) DeleteIf(block func(T) bool) Slice[T]
- func (a Slice[T]) Drop(count int) Slice[T]
- func (a Slice[T]) Each(block func(T))
- func (a Slice[T]) EachIndex(block func(int))
- func (a Slice[T]) Fetch(index int, defaultValue T) T
- func (a Slice[T]) Fill(element T, start int, length int) Slice[T]
- func (a Slice[T]) FillWith(start int, length int, block func(int) T) Slice[T]
- func (a Slice[T]) First() *T
- func (a Slice[T]) Firsts(count int) Slice[T]
- func (a Slice[T]) Include(element T) bool
- func (a Slice[T]) Index(element T) int
- func (a Slice[T]) IndexBy(block func(T) bool) int
- func (a Slice[T]) Insert(index int, elements ...T) Slice[T]
- func (a Slice[T]) IsEmpty() bool
- func (a Slice[T]) IsEq(other Slice[T]) bool
- func (a Slice[T]) KeepIf(block func(T) bool) Slice[T]
- func (a Slice[T]) Last() *T
- func (a Slice[T]) Lasts(count int) Slice[T]
- func (a Slice[T]) Len() int
- func (a Slice[T]) Map(block func(T) T) Slice[T]
- func (a Slice[T]) Max(block func(T) int) T
- func (a Slice[T]) Min(block func(T) int) T
- func (a Slice[T]) Pop() (Slice[T], T)
- func (a Slice[T]) Push(element T) Slice[T]
- func (a Slice[T]) Reduce(block func(T) bool) Slice[T]
- func (a Slice[T]) Reverse() Slice[T]
- func (a Slice[T]) Select(block func(T) bool) Slice[T]
- func (a Slice[T]) SelectUntil(block func(T) bool) Slice[T]
- func (a Slice[T]) Shift() (T, Slice[T])
- func (a Slice[T]) Shuffle() Slice[T]
- func (a Slice[T]) Unique() Slice[T]
- func (a Slice[T]) Unshift(element T) Slice[T]
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Map ¶ added in v0.0.4
type Map[K comparable, V any] struct { // contains filtered or unexported fields }
Map is a wrapper for sync.Map with same methods (except for CompareAnd*) Check: https://pkg.go.dev/sync#Map
func (*Map[K, V]) Delete ¶ added in v0.0.4
func (m *Map[K, V]) Delete(k K)
Delete see sync.Map#Delete
func (*Map[K, V]) LoadAndDelete ¶ added in v0.0.4
LoadAndDelete see sync.Map#LoadAndDelete
func (*Map[K, V]) LoadOrStore ¶ added in v0.0.4
LoadOrStore see sync.Map#LoadOrStore
type Slice ¶
type Slice[T comparable] []T
Slice is an alias for a slice of variables that vary in types Slice can hold any comparable data type
Example ¶
a := Slice[int]{1, 2, 3, 4, 5, 6} // multiply every element by 100 a = a.Map(func(e int) int { return e * 100 }) // select any element <= 300 a = a.KeepIf(func(e int) bool { return e <= 300 }) fmt.Print(a)
Output: [100 200 300]
func (Slice[T]) All ¶
All returns true if "block" returned true for all elements in Slice and false otherwise
func (Slice[T]) Any ¶
Any returns true if "block" returned true for any of the Slice elements and false otherwise
func (Slice[T]) At ¶
At returns element by index, a negative index counts from the end of the Slice if index is out of range it returns nil
func (Slice[T]) CountElement ¶
CountElement returns number of elements equal to "element" in Slice
func (Slice[T]) Cycle ¶
Cycle will cycle through Slice elements "count" times passing each element to "block" function
func (Slice[T]) Drop ¶
Drop will return an array without the first "count" elements from the beginning
func (Slice[T]) Each ¶
func (a Slice[T]) Each(block func(T))
Each will execute "block" for each element in array
func (Slice[T]) Fetch ¶
Fetch will return the element in "index", if it doesn't exist it returns the passed "defaultValue"
func (Slice[T]) Fill ¶
Fill will replace elements inplace starting from "start" counting "length" elements with the passed "element" parameter, will return same array object
func (Slice[T]) FillWith ¶
FillWith will replace elements from start counting "length" items, passing every index to block and replacing the element inplace with the return value
func (Slice[T]) Firsts ¶
Firsts will return an array holding the first "count" elements of the array
func (Slice[T]) Index ¶
Index returns the index of the first element in array that is equal to "element", returns -1 if the elements if not found
func (Slice[T]) Insert ¶
Insert will insert a set of elements in the index and will return a new array
func (Slice[T]) KeepIf ¶
KeepIf will return an array contains all elements where "block" returned true for them
func (Slice[T]) Map ¶
Map will return a new array replacing every element from current array with the return value of the block
func (Slice[T]) Pop ¶
Pop removes the last element from the array, returning new array and the element
func (Slice[T]) Reverse ¶
Reverse will reverse the array in reverse returning the array reference again
func (Slice[T]) SelectUntil ¶ added in v0.0.2
SelectUntil selects from the start of the slice until the block returns true, excluding the item that returned true.
func (Slice[T]) Shift ¶
Shift will remove the first element of the array returning the element and a modified array
func (Slice[T]) Shuffle ¶
Shuffle will randomly shuffle an array elements order returning array reference again