slices

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2023 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Chunk

func Chunk[K comparable](slice []K, batchSize int) [][]K

Chunk - create batches of an arbitrary typed slice into the given batch size

func PickField

func PickField[K interface{}, V comparable](iterator []K, picker Picker[K, V]) []V

PickField - pick the value of a particular field from a slice into it's own slice using the given picker function

Types

type Picker added in v0.1.0

type Picker[K interface{}, V comparable] func([]K) []V

func PickWithFunc added in v0.1.0

func PickWithFunc[K interface{}, V comparable](pickerFunc func(K) V) Picker[K, V]

PickWithFunc get the key using a picker function

exampleSlice := []pickFieldTestType{{value: "wake up"}, {value: "code"}, {value: "repeat"}}

pickedSlices := slices.PickField(exampleSlice,
	slices.PickWithFunc(
		func(k pickFieldTestType) string {
			return k.value
		},
	))

func PickWithKey added in v0.1.0

func PickWithKey[K interface{}](field string) Picker[K, reflect.Value]

PickWithKey when working with a single field, you can use this picker to get the values from the passed generic type.

exampleSlice := []pickFieldTestType{{value: "wake up"}, {value: "code"}, {value: "repeat"}}

pickedSlices := slices.PickField(exampleSlice,
   slices.PickWithKey[pickFieldTestType]("value"),
)

Jump to

Keyboard shortcuts

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