slices

package
v2.0.0-...-82fddbe Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2025 License: MIT Imports: 1 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Chunk

func Chunk[T any](slice []T, chunkSize int) [][]T

Chunk takes a slice of values and a chunkSize, then returns a slice of the values in slices of chunkSize ex: Chunk({1,2,3,4,5,6,7,8},3) == {{1,2,3}{4,5,6}{7,8}}

func Filter

func Filter[T any](in []T, keep func(T) bool) (out []T)

Filter applies the keep function to each value in the input The result is a slice of only the values which returned true

func FilterInPlace

func FilterInPlace[T any](in []T, keep func(T) bool) (out []T)

TODO: changeMe The result is a slice of only the values which returned true

func Map

func Map[I, O any](data []I, mapFunc func(I) O) []O

Map returns a same-sized slice as the input data.

The value of each position in the output slice is the same position in the input slice modified by the mapFunc.

e.x. output[i] == mapFunc(data[i])

func MapToMap

func MapToMap[I any, O comparable, U any](data []I, mapFunc func(I) (O, U)) map[O]U

MapToMap // TODO: this

func ReverseOf

func ReverseOf[T any](s []T) []T

func ScanLeft

func ScanLeft[T constraints.Ordered](data []T, init T, op func(T, T) T) []T

ScanLeft creates a slice of size len(data)+1, where the first item is init. All other values in the output are the result of the provided operation

func Sliding

func Sliding[T any](data []T, groupSize int) [][]T

Sliding takes an input slice and a groupsize. ex: sliding({1,2,3,4,5,6,7},3) == {{1,2,3}, For each value in the slice that has groupsize-1 values after it, {2,3,4}, add a slice of {data[i], data[i+1],...,data[i+groupsize-1]} to the output {3,4,5},

func Unique

func Unique[T comparable](in []T) []T

func UniqueInPlace

func UniqueInPlace[T comparable](in []T) []T

UniqueInPlace modifies the input! The output may be a different size than the input!

func Zip

func Zip[T any](L, R []T) [][2]T

Zip takes two slices and "zips" them together into pairs, dropping unpaired values for example L={1,2,3} R={4,5,6} becomes {{1,4}{2,5}{3,6}} and L={1,2,3} R={4,5,6,7} becomes {{1,4}{2,5}{3,6}}

Types

This section is empty.

Jump to

Keyboard shortcuts

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