Documentation ¶
Overview ¶
TODO doc comment for whole array package
Index ¶
- Constants
- Variables
- func Unwrap[T comparable](of *Of[T]) *[]T
- type Of
- func Each[T comparable](input *Of[T], visitor func(v *T, k int, input *Of[T]) (exit bool)) *Of[T]
- func From[T comparable](source []T) *Of[T]
- func FromWarn[T comparable](source []T) *Of[T]
- func Make[T comparable](initial_capacity int) *Of[T]
- func MakeWarn[T comparable](initial_capacity int) *Of[T]
- func Map[T comparable, O comparable](input *Of[T], converter func(v *T, k int, input *Of[T]) O) *Of[O]
- func MapWarn[T comparable, O comparable](input *Of[T], converter func(v *T, k int, input *Of[T]) O) *Of[O]
- func Wrap[T comparable](original *[]T) *Of[T]
- func WrapWarn[T comparable](original *[]T) *Of[T]
- func (array *Of[T]) AllIndexesByValue(value T) *Of[int]
- func (array *Of[T]) AllIndexesByValueFunc(condition func(other T) bool) *Of[int]
- func (arr *Of[T]) At(index int) *T
- func (arr *Of[T]) Every(condition func(v T, k int, source *Of[T]) bool) bool
- func (arr *Of[T]) Filter(condition func(v T, k int, source *Of[T]) bool) (output *Of[T])
- func (arr *Of[T]) FirstIndexByValue(value T) int
- func (array *Of[T]) FirstIndexByValueFunc(condition func(other T) bool) int
- func (arr *Of[T]) FirstIndexOfReference(value *T) int
- func (arr *Of[T]) FirstIndexOfReferenceFunc(condition func(v *T) bool) int
- func (arr *Of[T]) FirstIndexOfReferenceWarn(value *T) int
- func (array *Of[T]) LastIndexByValue(value T) int
- func (array *Of[T]) LastIndexByValueFunc(condition func(other T) bool) int
- func (arr *Of[T]) Length() int
- func (arr *Of[T]) Push(values ...T) *Of[T]
- func (arr *Of[T]) PushMissing(values ...T) *Of[T]
- func (arr *Of[T]) Slice(from int, to int) *Of[T]
Constants ¶
const ( WARN_ABOUT_NOTHING = 1 << iota WARN_ABOUT_BAD_NIL_ARGUMENTS WARN_ABOUT_BAD_EQUATABLE )
const ( IS_NIL = -1 IS_EMPTY = -2 NOT_FOUND = -3 NIL_REF = -4 )
const EV_FOOTPRINT = "Equals has the wrong footprint\n\texpected func (%s) Equals(%s)\n\tgot func (%s) Equals(%s)\n"
Variables ¶
var WARN_IS_FATAL = false
var WARN_ME_ABOUT = WARN_ABOUT_NOTHING
var WARN_ME_WITH_STACK = false
Functions ¶
func Unwrap ¶
func Unwrap[T comparable](of *Of[T]) *[]T
Unwraps *array.Of[T] to *[]T with the same pointer as of
Types ¶
type Of ¶
type Of[T comparable] []T
func Each ¶
Runs visitor over each index of input
breaks out of the loop if visitor returns true
returns input
func From ¶
func From[T comparable](source []T) *Of[T]
Creates a new array.Of[T] with a different pointer than from
all values should be understood to be handled the same as from := append([]T{}, source...)
func FromWarn ¶
func FromWarn[T comparable](source []T) *Of[T]
Creates a new array.Of[T] with a different pointer than source
if array.WARN_ME_ABOUT has bit array.WARN_ABOUT_BAD_EQUATABLE set it will log any mismatch between T and EquatableValue
all values should be understood to be handled the same as from := append([]T{}, source...)
func Make ¶
func Make[T comparable](initial_capacity int) *Of[T]
Creates a new array.Of[T] with len of initial_capacity
func MakeWarn ¶
func MakeWarn[T comparable](initial_capacity int) *Of[T]
Creates a new array.Of[T] with len of initial_capacity
if array.WARN_ME_ABOUT has bit array.WARN_ABOUT_BAD_EQUATABLE set it will log any mismatch between T and EquatableValue
func Map ¶
func Map[T comparable, O comparable](input *Of[T], converter func(v *T, k int, input *Of[T]) O) *Of[O]
Runs converter over each index of input and adds the output to the same index of its return value
func MapWarn ¶
func MapWarn[T comparable, O comparable](input *Of[T], converter func(v *T, k int, input *Of[T]) O) *Of[O]
Runs converter over each index of input and adds the output to the same index of its return value
if array.WARN_ME_ABOUT has bit array.WARN_ABOUT_BAD_EQUATABLE set it will log any mismatch between T or O and EquatableValue
func Wrap ¶
func Wrap[T comparable](original *[]T) *Of[T]
Wraps original as *array.Of[T] with the same pointer as original
func WrapWarn ¶
func WrapWarn[T comparable](original *[]T) *Of[T]
Creates a new array.Of[T] with the same pointer as source
if array.WARN_ME_ABOUT has bit array.WARN_ABOUT_BAD_EQUATABLE set it will log any mismatch between T and EquatableValue
func (*Of[T]) AllIndexesByValue ¶
Finds all occurrences of the element
evaluates a.Equals(b) if present on T before evaluating a == b
returns nil if arr (a pointer to Of[T], itself an array) is nil
returns an empty *Of[int] if the underlying array has no values
returns all indexes if any are found
returns an empty *Of[int] if nothing is found
func (*Of[T]) AllIndexesByValueFunc ¶
Finds the first occurrence of an element matching the condition
returns nil if arr (a pointer to Of[T], itself an array) is nil
returns an empty *Of[int] if the underlying array has zero elements
returns all indexes if any are found
returns an empty *Of[int] if nothing is found
func (*Of[T]) At ¶
returns nil if arr (a pointer to Of[T], itself an array) is nil
returns nil if index >= arr.Length() or if arr.Length()-index < 0
returns a reference to the value at index or, if index is less than zero, arr.Length()-index
func (*Of[T]) Every ¶
Tests whether all elements in the array pass the test implemented by the provided function.
returns false if arr (a pointer to Of[T], itself an array) is nil
returns true if condition returns true for all elements
func (*Of[T]) Filter ¶
Filters the array against a condition
returns a new empty array if arr (a pointer to Of[T], itself an array) is nil
returns a new array containing all matches
arr.At(n) does not have the same address as output.At(n)
func (*Of[T]) FirstIndexByValue ¶
Finds the first occurrence of the element
evaluates a.Equals(b) if present on T before evaluating a == b
returns array.IS_NIL if arr (a pointer to Of[T], itself an array) is nil
returns array.IS_EMPTY if the underlying array has no values
returns the index of the first result if it is found
returns array.NOT_FOUND if nothing is found
func (*Of[T]) FirstIndexByValueFunc ¶
Finds the first occurrence of an element matching the condition
returns array.IS_NIL if arr (a pointer to Of[T], itself an array) is nil
returns array.IS_EMPTY if the underlying array has zero elements
returns the index of the first result if it is found
returns array.NOT_FOUND if nothing is found
func (*Of[T]) FirstIndexOfReference ¶
Finds the first occurrence of an element with the same address as value
returns array.IS_NIL if arr (a pointer to Of[T], itself an array) is nil
returns array.IS_EMPTY if the underlying array has no values
returns the index of the first result if it is found
returns array.NOT_FOUND if nothing is found
func (*Of[T]) FirstIndexOfReferenceFunc ¶
Finds the first occurrence that satisfies condition(arr.At(i))
returns array.IS_NIL if arr (a pointer to Of[T], itself an array) is nil
returns array.IS_EMPTY if the underlying array has no values
returns the index of the first result if it is found
returns array.NOT_FOUND if nothing is found
func (*Of[T]) FirstIndexOfReferenceWarn ¶
Finds the first occurrence of an element with the same address as value
if array.WARN_ME_ABOUT has bit array.WARN_ABOUT_BAD_NIL_ARGUMENTS set it will log a warning when nil is passed to the function
returns the index of the first result if it is found
returns array.IS_NIL if arr (a pointer to Of[T], itself an array) is nil
returns array.IS_EMPTY if the underlying array has no values
returns array.NOT_FOUND if nothing is found
func (*Of[T]) LastIndexByValue ¶
Finds the last occurrence of the element
evaluates a.Equals(b) if present on T before evaluating a == b
returns array.IS_NIL if arr (a pointer to Of[T], itself an array) is nil
returns array.IS_EMPTY if the underlying array has no values
returns the index of the first result if it is found
returns array.NOT_FOUND if nothing is found
func (*Of[T]) LastIndexByValueFunc ¶
Finds the last occurrence of an element matching the condition
returns array.IS_NIL if arr (a pointer to Of[T], itself an array) is nil
returns array.IS_EMPTY if the underlying array has zero elements
returns the index of the first result if it is found
returns array.NOT_FOUND if nothing is found
func (*Of[T]) Length ¶
returns 0 if arr (a pointer to Of[T], itself an array) is nil
returns len(*arr)
func (*Of[T]) Push ¶
Adds the specified elements to the end of
noop if the array if arr (a pointer to Of[T], itself an array) is nil
returns itself (even if itself is nil).
func (*Of[T]) PushMissing ¶
Adds the specified elements to the end of an array only if the individual elements are not already in the array.
an element is evaluated to be in the array after the previous item is added
all elements will prioritize an Equatable evaluation before an == evaluation
noop if the array if arr (a pointer to Of[T], itself an array) is nil
returns itself (even if itself is nil).
func (*Of[T]) Slice ¶
returns nil if arr (a pointer to Of[T], itself an array) is nil
returns nil if from >= arr.Length() or if arr.Length()-from < 0
returns nil if to >= arr.Length() or if arr.Length()-to < 0
returns a pointer to a slice of arr[want_from:want_to] where want_ is arr.Length() - want_ if from or to are negative