gearslice

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2023 License: MIT Imports: 5 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Contact

func Contact[T any](args ...[]T) []T

Contact Concatenate multiple slices and return a new slice

func Count

func Count[T comparable](s []T, value T) int

Count return the number of elements in the slice that equal to value

func CountBy

func CountBy[T comparable](s []T, fn func(el T, index int) bool) int

CountBy return the number of the elements in the slice that pass the test implemented by the provided the function

func Drop

func Drop[T any](s []T, n int) ([]T, error)

Drop drops n elements from the beginning(if n greater than zero) or the end(if n less than zero) of the slice

func Every

func Every[T any](s []T, fn func(el T, index int) bool) bool

Every weather all elements in the slice passed the test implemented by the provided function

func Filter

func Filter[T any](s []T, filter func(el T, index int) bool) []T

Filter filtered down to just the elements from the given slice that passed the test implemented by the provided function

func Find

func Find[T any](s []T, fn func(el T, index int) bool) (T, bool)

Find return the value of the first element of the slice that passed the test function provided

func FindIndex

func FindIndex[T any](s []T, fn func(el T, index int) bool) int

FindIndex return the index of the first element in the slice that passed the test implemented by the provided function return -1 if no corresponding element is found

func FindLastIndex added in v1.0.1

func FindLastIndex[T any](s []T, fn func(el T, index int) bool) int

FindIndex return the index of the last element in the slice that passed the test implemented by the provided function return -1 if no corresponding element is found

func ForEach

func ForEach[T any](s []T, cb func(el T, index int))

ForEach execute a provided function once for each element in the slice

func Includes

func Includes[T comparable](s []T, el T) bool

Includes weather the slice contains a certain element

func IndexOf

func IndexOf[T comparable](s []T, el T) int

IndexOf return the index of the element in the slice, if the element is not in the slice, return -1

func Insert

func Insert[T any](s *[]T, index int, value T) error

Insert insert a value in the slice at a given index. it will modify the origin slice

func LastIndexOf added in v1.0.1

func LastIndexOf[T comparable](s []T, el T) int

LastIndexOf return the last index of the element in the slice, if the element is not in the slice, return -1

func Map

func Map[T, K any](s []T, cb func(el T, index int) K) []K

Map create a new slice populated with the results of calling the provide function on every element in the calling slice

func Pop

func Pop[T any](s *[]T) T

Pop removes the last element from a slice and return that element, return the removed element. it will change the length of the slice

func Remove

func Remove[T any](s *[]T, index int) error

Remove remove a value in the slice at a given index. it will modify the origin slice

func Reverse

func Reverse[T any](s []T) []T

Reverse reverse a slice, return a new slice

func Sample

func Sample[T any](s []T) T

Sample get a random element from the slice

func Shift

func Shift[T any](s *[]T) T

Shift removes the first element from a slice and return that removed element. This method changes the length of the slice

func Some

func Some[T any](s []T, fn func(el T, index int) bool) bool

Some weather at least one element in the slice passed the test implemented by the provide function

func Uniq

func Uniq[T constraints.Ordered | constraints.Complex](s []T) []T

Uniq remove duplicate elements in the slice

Types

This section is empty.

Jump to

Keyboard shortcuts

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