array

package
v0.0.12 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2024 License: MIT Imports: 0 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func All added in v0.0.11

func All[T any](arr []T, check func(elem T) bool) bool

All will check if all element of 'arr' respect the condition 'check'

func Compare added in v0.0.12

func Compare[T comparable](arr1, arr2 []T) bool

Compare two array with operator == on their element array of different size are not equal

func CompareWith added in v0.0.12

func CompareWith[T any](arr1, arr2 []T, cmp func(elem1, elem2 T) bool) bool

Compare two array with cmp function on their element array of different size are not equal

func Filter added in v0.0.10

func Filter[T any](arr []T, filter func(elem T) bool) []T

Filter will generate a new slice containing only element that match the filter function (a match mean the function returns true)

func FindElem added in v0.0.11

func FindElem[T comparable](arr []T, elem T) (int, bool)

FindElem will return the index to the first element from 'arr' where 'arr[i] == elem' (with 'i' the index) it also returns a boolean set to true if the element is found and false otherwise If the element is not found the index is set to 0

func FindElemRef added in v0.0.11

func FindElemRef[T comparable](arr []T, elem T) (*T, bool)

FindElemRef will return a reference to the first element from 'arr' equal to 'elem' (using '==') along with a boolean that indicate if the element is found if the element is not found the boolean is false and the pointer is nil

func FindMatch added in v0.0.11

func FindMatch[T any](arr []T, match func(T) bool) (int, bool)

FindMatch do the same thing than FindMatchRef except it return the index instead of a reference it return 0 if the element is not found

func FindMatchRef added in v0.0.11

func FindMatchRef[T any](arr []T, match func(T) bool) (*T, bool)

FindMatchRef will return the reference of the first element from 'arr' where 'match' is true it also returns a boolean that indicate wether the element is found or not if the element is not found, the pointer is nil

func ForEach added in v0.0.11

func ForEach[T any](arr []T, action func(elem T) (breaking Break))

ForEach apply action like a for-range loop on a slice

func ForEachReverse added in v0.0.10

func ForEachReverse[T any](arr []T, action func(elem T) (breaking Break))

ForEachReverse apply action like a for-range loop on a slice, in reversed order

func Map added in v0.0.10

func Map[T1, T2 any](arr []T1, action func(elem T1) T2) []T2

Map allows to generate a new slice from value of an existing one. If you need to get references of the existing slice use MapRef

func MapRef added in v0.0.10

func MapRef[T1, T2 any](arr []T1, action func(elem *T1) T2) []T2

MapRef allows to generate a new slice from reference's value of an existing one. If you don't need reference use Map

func Reduce added in v0.0.11

func Reduce[T any](arr []T, reduce func(reduced, elem T) T) T

Reduce like ReduceAs except the result type is the same as the array type.

func ReduceAs added in v0.0.11

func ReduceAs[T1, T2 any](arr []T1, reduce func(reduced T2, elem T1) T2) T2

ReduceAs reduce the array 'arr' with the function reduce with possible different result type

func Reversed added in v0.0.10

func Reversed[T any](arr []T) []T

Reversed reverse the given slice

Types

type Break added in v0.0.10

type Break bool

Break is a way to represent the break statement in a for loop; true mean breaking the loop this is to use as a function return type.

Jump to

Keyboard shortcuts

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