Documentation ¶
Index ¶
- func Coalesce[T comparable](ts ...T) T
- func Every[T any](in []T, f func(T, int, []T) bool) bool
- func Filter[T any](in []T, f func(T, int, []T) bool) []T
- func Find[T any](in []T, f func(T, int, []T) bool) T
- func FindIndex[T any](in []T, f func(T, int, []T) bool) int
- func ForEach[T any](in []T, f func(T, int, []T))
- func Includes[T comparable](in []T, a T) bool
- func IndexOf[T comparable](in []T, a T) int
- func Join[T fmt.Stringer](in []T, separator string) string
- func LastIndexOf[T comparable](in []T, a T, from int) int
- func Map[T1, T2 any](in []T1, f func(T1, int, []T1) T2) []T2
- func Reduce[T1, T2 any](in []T1, f func(T2, T1, int, []T1) T2, initial T2) T2
- func ReduceRight[T1, T2 any](in []T1, f func(T2, T1, int, []T1) T2, initial T2) T2
- func Reverse[T any](in []T) []T
- func Slice[T any](in []T, start, end int) []T
- func Some[T any](in []T, f func(T, int, []T) bool) bool
- func Sort[T comparable](in []T, f func(a, b T) int) []T
- func Ternary[T any](condition bool, a, b T) T
- func Unique[T comparable](in []T) []T
- type AnyArray
- func (a AnyArray[T]) Every(f func(T, int, []T) bool) bool
- func (a AnyArray[T]) Filter(f func(T, int, []T) bool) AnyArray[T]
- func (a AnyArray[T]) Find(f func(T, int, []T) bool) T
- func (a AnyArray[T]) FindIndex(f func(T, int, []T) bool) int
- func (a AnyArray[T]) ForEach(f func(T, int, []T))
- func (a AnyArray[T]) Reverse() AnyArray[T]
- func (a AnyArray[T]) Slice(start, end int) AnyArray[T]
- func (a AnyArray[T]) Some(f func(T, int, []T) bool) bool
- type ComparableArray
- type MappableArray
- type ReducibleArray
- type StringerArray
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Coalesce ¶
func Coalesce[T comparable](ts ...T) T
Coalesce is meant to represent the '||' operator e.g.
const myVar = otherVar || 'default';
It returns the first non-zero-valued instance of T that it finds, or the zero value of T if it finds none.
func Every ¶
Every tests whether all elements in the array pass the test implemented by the provided function. It returns a Boolean value.
func Filter ¶
Filter creates a new array with all elements that pass the test implemented by the provided function.
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 Map ¶
Map creates a new array populated with the results of calling a provided function on every element in the calling array.
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 Reverse ¶
func Reverse[T any](in []T) []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 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 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 ¶
func Sort[T comparable](in []T, f func(a, b T) int) []T
Sort creates a new array by sorting the elements of the given array and returns the sorted array. The sort order is ascending.
func Ternary ¶
Ternary returns the first T if the conditional evaluates to true, otherwise it returns the second T
func Unique ¶
func Unique[T comparable](in []T) []T
Unique creates a new array with only unique elements from the given array.
Types ¶
type AnyArray ¶
type AnyArray[T any] []T
AnyArray is an array of any and has methods that mimic a subset of the JavaScript array functions.
func (AnyArray[T]) Every ¶
Every tests whether all elements in the array pass the test implemented by the provided function. It returns a Boolean value.
func (AnyArray[T]) Filter ¶
Filter creates a new array with all elements that pass the test implemented by the provided function.
func (AnyArray[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 (AnyArray[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 (AnyArray[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 (AnyArray[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 ComparableArray ¶
type ComparableArray[T comparable] AnyArray[T]
ComparableArray is an array of fmt.Comparable and has methods that mimic a subset of the JavaScript array functions that are unique to comparables.
func (ComparableArray[T]) Includes ¶
func (a ComparableArray[T]) Includes(b T) bool
Includes determines whether an array includes a certain value among its entries, returning true or false as appropriate.
func (ComparableArray[T]) IndexOf ¶
func (a ComparableArray[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 (ComparableArray[T]) LastIndexOf ¶
func (a ComparableArray[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 (ComparableArray[T]) Unique ¶
func (a ComparableArray[T]) Unique() ComparableArray[T]
Unique creates a new array with only unique elements from the given array.
type MappableArray ¶
MappableArray is an array of any and has methods that mimic the JavaScript array map function.
T1 represents the type of the array, while T2 represents the type of the array intended to be mapped to
func (MappableArray[T1, T2]) Map ¶
func (a MappableArray[T1, T2]) Map(f func(T1, int, []T1) T2) AnyArray[T2]
Map creates a new array populated with the results of calling a provided function on every element in the calling array.
type ReducibleArray ¶
ReducibleArray 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 accumulator intended to be used when reducing.
func (ReducibleArray[T1, T2]) Reduce ¶
func (a ReducibleArray[T1, T2]) Reduce(f func(T2, T1, int, []T1) 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 (ReducibleArray[T1, T2]) ReduceRight ¶
func (a ReducibleArray[T1, T2]) ReduceRight(f func(T2, T1, int, []T1) 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.
type StringerArray ¶
StringerArray is an array of fmt.Stringer and has methods that mimic a subset of the JavaScript array functions that are unique to fmt.Stringers.
func (StringerArray[T]) Join ¶
func (a StringerArray[T]) Join(separator string) string
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.
Source Files ¶
- any_array.go
- array_every.go
- array_filter.go
- array_find.go
- array_find_index.go
- array_for_each.go
- array_includes.go
- array_index_of.go
- array_join.go
- array_last_index_of.go
- array_map.go
- array_reduce.go
- array_reduce_right.go
- array_reverse.go
- array_slice.go
- array_some.go
- array_sort.go
- array_unique.go
- comparable_array.go
- mappable_array.go
- or_operator.go
- reducible_array.go
- stringer_array.go
- ternary_operator.go