slice

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2022 License: MIT Imports: 3 Imported by: 1

Documentation

Overview

Package slice contains generic utility functions on slices

Package slice contains generic utility functions on slices

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Contains

func Contains[T comparable](l []T, v T) bool

Contains checks for the existence of an element in the slice

func Deduplicate

func Deduplicate[T comparable](in []T) []T

Deduplicate deduplicates a slice

func DumbSort

func DumbSort[T constraints.Ordered](ts []T) []T

DumbSort ...

func Filter

func Filter[T any](in []T, f func(T) bool) (out []T)

Filter filters a slice using the given function

func Fold

func Fold[A, B any](as []A, f func(A, B) B, acc B) B

Fold folds the slice into a single value using the given function and accumulator

func Index

func Index[T comparable](ts []T, v T) int

Index returns the index of a value if it exists it will return -1 if it does not exist in the slice

func Intersect

func Intersect[T comparable](as []T, bs []T) (ts []T)

Intersect returns the intersection of two slices

func Map

func Map[A, B any](as []A, f func(A) B) []B

Map create a new slice from an existing one using a map function

func MapFilter

func MapFilter[A, B any](slice []A, f func(A) (B, bool)) (out []B)

MapFilter combines Map and Filter into one process It takes a function that takes a value of type A and returns a value of type B, and a bool for whether or not to keep the value.

func Reduce

func Reduce[A, B any](as []A, f func(A, B) B, acc B) B

Reduce reduces the slice to a single value using the given fucntion and accumulator

func Remove

func Remove[T comparable](xs []T, d T) []T

Remove will remove from the slice the first match of the given value

func RemoveAll

func RemoveAll[T comparable](xs []T, v T) []T

RemoveAll removes all occurances of the given value in the slice

func Reverse

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

Reverse reverses the order of a slice

func Shuffle

func Shuffle[T any](l []T) []T

Shuffle shuffles a slice using the Fisher-Yates algorithm you need to call `rand.Seed` for this to work properly

func Sort

func Sort[T constraints.Ordered](ts []T) []T

Sort will sort a slice

func ToMap

func ToMap[K comparable, V, A any](as []A, f func(A) (K, V)) map[K]V

ToMap converts a slice to a map using the given function which takes an element and returns a key and value

Types

This section is empty.

Jump to

Keyboard shortcuts

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