array

package
v0.0.0-...-13632b2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 28, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

TODO doc comment for whole array package

Index

Constants

View Source
const (
	WARN_ABOUT_NOTHING = 1 << iota
	WARN_ABOUT_BAD_NIL_ARGUMENTS
	WARN_ABOUT_BAD_EQUATABLE
)
View Source
const (
	IS_NIL    = -1
	IS_EMPTY  = -2
	NOT_FOUND = -3
	NIL_REF   = -4
)
View Source
const EV_FOOTPRINT = "Equals has the wrong footprint\n\texpected func (%s) Equals(%s)\n\tgot func (%s) Equals(%s)\n"

Variables

View Source
var WARN_IS_FATAL = false
View Source
var WARN_ME_ABOUT = WARN_ABOUT_NOTHING
View Source
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

func Each[T comparable](input *Of[T], visitor func(v *T, k int, input *Of[T]) (exit bool)) *Of[T]

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

func (array *Of[T]) AllIndexesByValue(value T) *Of[int]

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

func (array *Of[T]) AllIndexesByValueFunc(condition func(other T) bool) *Of[int]

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

func (arr *Of[T]) At(index int) *T

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

func (arr *Of[T]) Every(condition func(v T, k int, source *Of[T]) bool) bool

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

func (arr *Of[T]) Filter(condition func(v T, k int, source *Of[T]) bool) (output *Of[T])

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

func (arr *Of[T]) FirstIndexByValue(value T) int

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

func (array *Of[T]) FirstIndexByValueFunc(condition func(other T) bool) int

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

func (arr *Of[T]) FirstIndexOfReference(value *T) int

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

func (arr *Of[T]) FirstIndexOfReferenceFunc(condition func(v *T) bool) int

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

func (arr *Of[T]) FirstIndexOfReferenceWarn(value *T) int

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

func (array *Of[T]) LastIndexByValue(value T) int

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

func (array *Of[T]) LastIndexByValueFunc(condition func(other T) bool) int

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

func (arr *Of[T]) Length() int

returns 0 if arr (a pointer to Of[T], itself an array) is nil

returns len(*arr)

func (*Of[T]) Push

func (arr *Of[T]) Push(values ...T) *Of[T]

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

func (arr *Of[T]) PushMissing(values ...T) *Of[T]

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

func (arr *Of[T]) Slice(from int, to int) *Of[T]

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL