function

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func All

func All[T any](list []T, predicate func(T) bool) bool

All is a function that checks if all elements in a slice satisfy a predicate function.

func Any

func Any[T any](list []T, predicate func(T) bool) bool

Any is a function that checks if any element in a slice satisfies a predicate function.

func Contains

func Contains[T comparable](list []T, elem T) bool

Contains is a function that checks if a slice contains an element.

func ContainsWith

func ContainsWith[T any, K comparable](list []T, elem T, keyFn func(T) K) bool

ContainsWith is a function that checks if a slice contains an element based on a key function.

func Deduplicate

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

Deduplicate is a function that removes duplicates from a slice.

func DeduplicateWith

func DeduplicateWith[T any, K comparable](list []T, keyFn func(T) K) []T

DeduplicateWith is a function that removes duplicates from a slice based on a key function.

func Filter

func Filter[T any](list []T, predicate func(T) bool) []T

Filter is a function that filters a list based on a predicate function.

func Flatten

func Flatten[T any](list [][]T) []T

Flatten is a function that flattens a slice of slices.

func GroupBy

func GroupBy[T any, K comparable](list []T, keyFn func(T) K) map[K][]T

GroupBy is a function that groups elements in a slice by a common value, generated by a provided function.

func If

func If[T any](cond bool, ifVal, elseVal T) T

If is a function that returns a value if the condition is true, otherwise returns another value.

func IfElse

func IfElse[T any](cond bool, ifFn, elseFn func() T) T

IfElse is a function that returns a value if the condition is true, otherwise returns the result of another function.

func IfThen

func IfThen[T any](cond bool, val T, apply func(T) T) T

IfThen is a function that applies a function to a value if the condition is true, otherwise returns the value.

func Map

func Map[T, U any](list []T, mapper func(T) U) []U

Map is a function that maps a list of items to another list of items based on a function.

func Max

func Max[T number](list []T) (val T, ok bool)

Max is a function that returns the maximum element in a slice.

func MaxWith

func MaxWith[T any](list []T, less func(t1, t2 T) bool) (val T, ok bool)

MaxWith is a function that returns the maximum element in a slice based on a comparison function.

func Min

func Min[T number](list []T) (val T, ok bool)

Min is a function that returns the minimum element in a slice.

func MinWith

func MinWith[T any](list []T, less func(t1, t2 T) bool) (val T, ok bool)

MinWith is a function that returns the minimum element in a slice based on a comparison function.

func None

func None[T any](list []T, predicate func(T) bool) bool

None is a function that checks if no elements in a slice satisfy a predicate function.

func Partition

func Partition[T any](list []T, predicate func(T) bool) (satisfied, unsatisfied []T)

Partition is a function that partitions a slice into two slices based on a predicate function. The first slice contains elements that satisfy the predicate, and the second slice contains elements that do not.

func Reverse

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

Reverse is a function that reverses a slice.

func Sum

func Sum[T number](list []T) T

Sum is a function that returns the sum of elements in a slice.

func TopK

func TopK[T any](list []T, k int, cmp func(t1, t2 T) int) []T

TopK is a function that returns the top k elements in a slice based on a comparison function. cmp should return a positive number if t1 is greater than t2, a negative number if t1 is cmp than t2, and 0 if they are equal. The function uses a min heap to keep track of the top k elements.

Types

This section is empty.

Jump to

Keyboard shortcuts

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