goslice

package module
v0.0.0-...-fb11eb9 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2022 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllOf

func AllOf[T any](elems []T, pred func(elem T) bool) bool

AllOf returns true if and only if all of the elements in the slice satisfy the given predicate.

func AnyOf

func AnyOf[T any](elems []T, pred func(elem T) bool) bool

AnyOf returns true if and only if at least one of the elements in the slice satisfy the given predicate.

func BinarySearch

func BinarySearch[T constraints.Ordered](elems []T, target T) (index int)

BinarySearch returns the index of the given target in the provided sorted elems slice. If the target is not in the sorted slice, -1 is returned.

func CountIf

func CountIf[T any](elems []T, pred func(elem T) bool) (count int)

CountIf returns the number of elements in the slice that satisfy the given predicate.

func Filter

func Filter[T any](elems []T, p func(T) bool) (r []T)

Filter returns all elements that satisfy the given predicate in a new slice.

func FilterNot

func FilterNot[T any](elems []T, p func(T) bool) (r []T)

Filter returns all elements that do NOT satisfy the given predicate in a new slice.

func FindIf

func FindIf[T any](elems []T, pred func(elem T) bool) int

FindIf returns the index to the first element in the slice that satisfies the given predicate. If no such element exists, -1 is returned.

func Map

func Map[T any, U any](elems []T, f func(T) U) (r []U)

Map applies the given function to each slice element and returns the resultant slice.

func Max

func Max[T constraints.Ordered](x, y T) T

func Merge

func Merge[T constraints.Ordered](left, right []T) (sorted []T)

Merge merges the two provided sorted slices into a single sorted slice.

func Min

func Min[T constraints.Ordered](x, y T) T

func NoneOf

func NoneOf[T any](elems []T, pred func(elem T) bool) bool

NoneOf returns true if and only if none of the elements in the slice satisfy the given predicate.

func ProdSlice

func ProdSlice[T constraints.Integer | constraints.Float](elems []T) T

ProdSlice returns the product of all the elemenst in the given slice. No attempt is made to detect overflow.

func Reduce

func Reduce[T any, U any](elems []T, f func(a U, b T) U, initial U) (r U)

Reduce reduces the given slice to a single value using the given function and initial value.

func SumSlice

func SumSlice[T constraints.Ordered](elems []T) T

SumSlice returns the sum of all the elements in the given slice. No attempt is made to detect overflow.

Types

type Pair

type Pair[T any, U any] struct {
	First  T
	Second U
}

func MakePair

func MakePair[T any, U any](first T, second U) Pair[T, U]

func Zip

func Zip[T any, U any](r1 []T, r2 []U) (r []Pair[T, U])

Zip zips the two given slices into a single slice.

func ZipLongest

func ZipLongest[T any, U any](r1 []T, r2 []U) (r []Pair[T, U])

Jump to

Keyboard shortcuts

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