sliceale

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyMapFunction

func ApplyMapFunction[T1, T2 any](s []T2, f func(T2) T1) []T1

ApplyMapFunction applies the function to each element of the slice and returns a new slice of the results in the same order. Don't confuse with the data structure `map` More info at: https://en.wikipedia.org/wiki/Map_(higher-order_function)

func ApplyMapFunctionRemovingDuplicates

func ApplyMapFunctionRemovingDuplicates[T1 comparable, T2 any](s []T2, f func(T2) T1) []T1

ApplyMapFunctionRemovingDuplicates applies the function to each element of the slice and returns a new slice of the results in the same order, but without duplicates.

func ApplyReduceFunction

func ApplyReduceFunction[T1, T2 any](s []T1, f func(T1, T2) T2, initVal T2) T2

ApplyReduceFunction applies a function to each element of the slice and returns a single value. It can also be called a `Fold`. This specific implementation is equivalent to a foldl More info at: https://en.wikipedia.org/wiki/Fold_(higher-order_function)

func GroupBy

func GroupBy[T1 any, T2 comparable](slice []T1, projection func(T1) T2) map[T2][]T1

GroupBy groups the elements of the slice into a new map, where the keys are the result of the projection and the values are the elements of the slice with that projection. WARNING: don't assume any order in the slices of the values of the map. The original order is not preserved.

func GroupByUniqueProjection

func GroupByUniqueProjection[T1 any, T2 comparable](slice []T1, projection func(T1) T2) (map[T2]T1, error)

GroupByUniqueProjection groups the elements of the slice by the result of the given function. If two elements have the same projection, it returns an error.

func GroupByWithJoinFunction

func GroupByWithJoinFunction[TOrig any, TKey comparable, TValue any](slice []TOrig, projection func(TOrig) TKey, join func(TOrig, TValue) TValue) map[TKey]TValue

GroupByWithJoinFunction groups the elements of the slice by the result of the given "projection" function and joins the result with the previous elements in that group using the "join" function" WARNING: don't assume any order in the join function. The original order is not guaranteed

func HasDuplicateField

func HasDuplicateField[T1 any, T2 comparable](elems []T1, projector func(T1) T2) bool

HasDuplicateField returns true if the slice has at least two elements with the same value when projected by the given function.

func IsOneOf

func IsOneOf[T comparable](s []T, elem T) bool

IsOneOf returns true iff the element is in the slice.

func RemoveDuplicates

func RemoveDuplicates[T1 comparable](s []T1) []T1

RemoveDuplicates returns a new slice with the same elements as the input slice, but without duplicates.

func Select

func Select[T any](slice []T, condition func(T) bool) []T

Select applies the given function to each element in the slice and returns a new slice containing only the elements that satisfy the function.

Types

This section is empty.

Jump to

Keyboard shortcuts

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