Documentation ¶
Index ¶
- func Coalesce[T comparable](ts ...T) T
- func Every[T any](in []T, f func(T, int) bool) bool
- func Find[T any](in []T, f func(T, int) bool) T
- func FindIndex[T any](in []T, f func(T, int) bool) int
- func ForEach[T any](in []T, f func(T, int))
- func Includes[T comparable](in []T, a T) bool
- func IndexOf[T comparable](in []T, a T) int
- func Join[T any](in []T, separator string) string
- func LastIndexOf[T comparable](in []T, a T, from int) int
- func Ptr[T any](t T) *T
- func Reduce[T1, T2 any](in []T1, f func(T2, T1, int) T2, initial T2) T2
- func ReduceRight[T1, T2 any](in []T1, f func(T2, T1, int) T2, initial T2) T2
- func Some[T any](in []T, f func(T, int) bool) bool
- func Sort[T any](in []T, f func(a, b T) int) []T
- func Unique[T comparable](in []T) []T
- type AnySlice
- func (a AnySlice[T]) Every(f func(T, int) bool) bool
- func (a AnySlice[T]) Filter(f func(T, int) bool) AnySlice[T]
- func (a AnySlice[T]) Find(f func(T, int) bool) T
- func (a AnySlice[T]) FindIndex(f func(T, int) bool) int
- func (a AnySlice[T]) ForEach(f func(T, int))
- func (a AnySlice[T]) Reverse() AnySlice[T]
- func (a AnySlice[T]) Slice(start, end int) AnySlice[T]
- func (a AnySlice[T]) Some(f func(T, int) bool) bool
- type ComparableSlice
- func (a ComparableSlice[T]) Filter(f func(T, int) bool) ComparableSlice[T]
- func (a ComparableSlice[T]) Includes(b T) bool
- func (a ComparableSlice[T]) IndexOf(b T) int
- func (a ComparableSlice[T]) LastIndexOf(b T, from int) int
- func (a ComparableSlice[T]) Reverse() ComparableSlice[T]
- func (a ComparableSlice[T]) Slice(start, end int) ComparableSlice[T]
- func (a ComparableSlice[T]) Unique() ComparableSlice[T]
- type ReducibleSlice
- func (a ReducibleSlice[T1, T2]) Filter(f func(T1, int) bool) ReducibleSlice[T1, T2]
- func (a ReducibleSlice[T1, T2]) Map(f func(T1, int) T2) AnySlice[T2]
- func (a ReducibleSlice[T1, T2]) Reduce(f func(T2, T1, int) T2, initial T2) T2
- func (a ReducibleSlice[T1, T2]) ReduceRight(f func(T2, T1, int) T2, initial T2) T2
- func (a ReducibleSlice[T1, T2]) Reverse() ReducibleSlice[T1, T2]
- func (a ReducibleSlice[T1, T2]) Slice(start, end int) ReducibleSlice[T1, T2]
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Coalesce ¶
func Coalesce[T comparable](ts ...T) T
func Every ¶
Every tests whether all elements in the array pass the test implemented by the provided function. It returns a Boolean value.
func Find ¶
Find returns the first element in the provided array that satisfies the provided testing function. If no values satisfy the testing function, the zero value of T is returned.
func FindIndex ¶
FindIndex returns the index of the first element in the array that satisfies the provided testing function. Otherwise, it returns -1, indicating that no element passed the test.
func Includes ¶
func Includes[T comparable](in []T, a T) bool
Includes determines whether an array includes a certain value among its entries, returning true or false as appropriate.
func IndexOf ¶
func IndexOf[T comparable](in []T, a T) int
IndexOf returns the first index at which a given element can be found in the array, or -1 if it is not present.
func Join ¶
Join creates and returns a new string by concatenating all of the elements in an array (or an array-like object), separated by commas or a specified separator string. If the array has only one item, then that item will be returned without using the separator.
func LastIndexOf ¶
func LastIndexOf[T comparable](in []T, a T, from int) int
LastIndexOf returns the last index at which a given element can be found in the array, or -1 if it is not present. The array is searched backwards, starting at fromIndex.
func Reduce ¶
Reduce executes a user-supplied "reducer" callback function on each element of the array, in order, passing in the return value from the calculation on the preceding element. The final result of running the reducer across all elements of the array is a single value.
The first time that the callback is run there is no "return value of the previous calculation". If supplied, an initial value may be used in its place. Otherwise the array element at index 0 is used as the initial value and iteration starts from the next element (index 1 instead of index 0).
func ReduceRight ¶
ReduceRight applies a function against an accumulator and each value of the array (from right-to-left) to reduce it to a single value.
func Some ¶
Some tests whether at least one element in the array passes the test implemented by the provided function. It returns true if, in the array, it finds an element for which the provided function returns true; otherwise it returns false. It doesn't modify the array.
func Sort ¶
Sort creates a new array by sorting the elements of the given array and returns the sorted array. The sort order is ascending.
func Unique ¶
func Unique[T comparable](in []T) []T
Unique creates a new array with only unique elements from the given array.
Types ¶
type AnySlice ¶
type AnySlice[T any] []T
AnySlice is an array of any and has methods that mimic a subset of the JavaScript array functions.
func Filter ¶
Filter creates a new array with all elements that pass the test implemented by the provided function.
func Map ¶
Map creates a new array populated with the results of calling a provided function on every element in the calling array.
func Reverse ¶
Reverse creates a new array by reversing the given array. The first array element becomes the last, and the last array element becomes the first.
func Slice ¶
Slice returns a shallow copy of a portion of an array into a new array object selected from start to end (end not included) where start and end represent the index of items in that array. The original array will not be modified.
If start<0, it is treated as distance from the end of the array. If end<=0, it is treated as distance from the end of the array.
func (AnySlice[T]) Every ¶
Every tests whether all elements in the array pass the test implemented by the provided function. It returns a Boolean value.
func (AnySlice[T]) Filter ¶
Filter creates a new array with all elements that pass the test implemented by the provided function.
func (AnySlice[T]) Find ¶
Find returns the first element in the provided array that satisfies the provided testing function. If no values satisfy the testing function, the zero value of T is returned.
func (AnySlice[T]) FindIndex ¶
FindIndex returns the index of the first element in the array that satisfies the provided testing function. Otherwise, it returns -1, indicating that no element passed the test.
func (AnySlice[T]) Reverse ¶
Reverse creates a new array by reversing the given array. The first array element becomes the last, and the last array element becomes the first.
func (AnySlice[T]) Slice ¶
Slice returns a shallow copy of a portion of an array into a new array object selected from start to end (end not included) where start and end represent the index of items in that array. The original array will not be modified.
If start<0, it is treated as distance from the end of the array. If end<=0, it is treated as distance from the end of the array.
type ComparableSlice ¶
type ComparableSlice[T comparable] AnySlice[T]
ComparableSlice is an array of comparable and has methods that mimic a subset of the JavaScript array functions that are unique to comparables.
func (ComparableSlice[T]) Filter ¶
func (a ComparableSlice[T]) Filter(f func(T, int) bool) ComparableSlice[T]
Filter creates a new array with all elements that pass the test implemented by the provided function.
func (ComparableSlice[T]) Includes ¶
func (a ComparableSlice[T]) Includes(b T) bool
Includes determines whether an array includes a certain value among its entries, returning true or false as appropriate.
func (ComparableSlice[T]) IndexOf ¶
func (a ComparableSlice[T]) IndexOf(b T) int
IndexOf returns the first index at which a given element can be found in the array, or -1 if it is not present.
func (ComparableSlice[T]) LastIndexOf ¶
func (a ComparableSlice[T]) LastIndexOf(b T, from int) int
LastIndexOf returns the last index at which a given element can be found in the array, or -1 if it is not present. The array is searched backwards, starting at fromIndex.
func (ComparableSlice[T]) Reverse ¶
func (a ComparableSlice[T]) Reverse() ComparableSlice[T]
Reverse creates a new array by reversing the given array. The first array element becomes the last, and the last array element becomes the first.
func (ComparableSlice[T]) Slice ¶
func (a ComparableSlice[T]) Slice(start, end int) ComparableSlice[T]
Slice returns a shallow copy of a portion of an array into a new array object selected from start to end (end not included) where start and end represent the index of items in that array. The original array will not be modified.
If start<0, it is treated as distance from the end of the array. If end<=0, it is treated as distance from the end of the array.
func (ComparableSlice[T]) Unique ¶
func (a ComparableSlice[T]) Unique() ComparableSlice[T]
Unique creates a new array with only unique elements from the given array.
type ReducibleSlice ¶
ReducibleSlice is an array of any and has methods that mimic the JavaScript array reduce functions.
T1 represents the type of the array, while T2 represents the type of the array intended to be mapped to.
func (ReducibleSlice[T1, T2]) Filter ¶
func (a ReducibleSlice[T1, T2]) Filter(f func(T1, int) bool) ReducibleSlice[T1, T2]
Filter creates a new array with all elements that pass the test implemented by the provided function.
func (ReducibleSlice[T1, T2]) Map ¶
func (a ReducibleSlice[T1, T2]) Map(f func(T1, int) T2) AnySlice[T2]
Map creates a new array populated with the results of calling a provided function on every element in the calling array.
func (ReducibleSlice[T1, T2]) Reduce ¶
func (a ReducibleSlice[T1, T2]) Reduce(f func(T2, T1, int) T2, initial T2) T2
Reduce executes a user-supplied "reducer" callback function on each element of the array, in order, passing in the return value from the calculation on the preceding element. The final result of running the reducer across all elements of the array is a single value.
The first time that the callback is run there is no "return value of the previous calculation". If supplied, an initial value may be used in its place. Otherwise the array element at index 0 is used as the initial value and iteration starts from the next element (index 1 instead of index 0).
func (ReducibleSlice[T1, T2]) ReduceRight ¶
func (a ReducibleSlice[T1, T2]) ReduceRight(f func(T2, T1, int) T2, initial T2) T2
ReduceRight applies a function against an accumulator and each value of the array (from right-to-left) to reduce it to a single value.
func (ReducibleSlice[T1, T2]) Reverse ¶
func (a ReducibleSlice[T1, T2]) Reverse() ReducibleSlice[T1, T2]
Reverse creates a new array by reversing the given array. The first array element becomes the last, and the last array element becomes the first.
func (ReducibleSlice[T1, T2]) Slice ¶
func (a ReducibleSlice[T1, T2]) Slice(start, end int) ReducibleSlice[T1, T2]
Slice returns a shallow copy of a portion of an array into a new array object selected from start to end (end not included) where start and end represent the index of items in that array. The original array will not be modified.
If start<0, it is treated as distance from the end of the array. If end<=0, it is treated as distance from the end of the array.