util

package
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2023 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ChunkBy

func ChunkBy[T any](items []T, chunkSize int) (chunks [][]T)

ChunkBy splits a slice into chunks of a specified size.

func Contains

func Contains[T comparable](collection []T, element T) bool

Contains checks if the given element is present in the collection.

func CopyMap

func CopyMap[K, V comparable](m map[K]V) map[K]V

CopyMap creates a new copy of the given map and returns it.

func CosineSimilarity added in v0.0.6

func CosineSimilarity(matrix1, matrix2 [][]float64) float64

func Difference added in v0.0.10

func Difference[T comparable](list1 []T, list2 []T) []T

Difference returns the difference between two collections.

func Filter

func Filter[T any](collection []T, f func(e T, i int) bool) []T

Filter applies a filtering function to a collection and returns a new slice containing the elements that satisfy the provided predicate function.

func KeyDifference added in v0.0.9

func KeyDifference(map1, map2 map[string]any) []string

KeyDifference finds the keys that are present in one map and not in the other map.

func Keys

func Keys[M ~map[K]V, K comparable, V any](m M) []K

Keys returns the keys of the map m. The keys will be an indeterminate order.

func Map

func Map[T, U any](ts []T, f func(e T, i int) U) []U

Map manipulates a slice and transforms it to a slice of another type.

func MergeMaps

func MergeMaps[M ~map[K]V, K comparable, V any](src ...M) M

MergeMaps merges multiple maps into a single map and returns the merged result.

func OmitByKeys

func OmitByKeys[K comparable, V any](in map[K]V, keys []K) map[K]V

OmitByKeys creates a new map by omitting key-value pairs from the input map based on the specified keys.

func SumInt added in v0.0.6

func SumInt(slice []int) int

SumInt calculates the sum of all integers in the given slice.

func Uniq added in v0.0.10

func Uniq[T comparable](collection []T) []T

Uniq returns a new slice containing unique elements from the given collection.

Types

This section is empty.

Jump to

Keyboard shortcuts

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