slices

package
v0.2.5 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2022 License: MIT Imports: 0 Imported by: 0

README

slices

Generic operations on slices: map, reduce, split, and group by. Because writing for loops over and over is really boring.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GroupBy added in v0.2.4

func GroupBy[K comparable, V any](src []V, keyFn func(V) K) map[K][]V

GroupBy indexes the given values by the result of the key function.

func Map added in v0.2.0

func Map[A any, B any](src []A, mapper func(A) B) []B

Map converts from one type to another.

func MapErr added in v0.2.0

func MapErr[A any, B any](src []A, mapper func(A) (B, error)) ([]B, error)

MapErr allows the conversion to fail for any value that returns an error.

func Reduce added in v0.2.0

func Reduce[V any, R any](values []V, acc R, reducer func(val V, acc R) R) R

Reduce a slice to a single value given an initial accumulator value.

func ReduceErr added in v0.2.0

func ReduceErr[V any, R any](values []V, acc R, reducer func(val V, acc R) (R, error)) (R, error)

ReduceErr allows the reduction to fail for any value that returns an error.

func Split added in v0.2.0

func Split[X any](src []X, partLen int) [][]X

Split given slice into equal sized parts. The last part may have an unequal length if the size of the source slice is not divisible by the required length without leaving a remainder.

Types

This section is empty.

Jump to

Keyboard shortcuts

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