slices

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2026 License: BSD-3-Clause Imports: 2 Imported by: 0

Documentation

Overview

Package slices provides generic slice operations such as unique, filter, chunk, and flatten.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendBounded

func AppendBounded[T any](s []T, v T, limit int) []T

AppendBounded appends v while capping at limit elements, shifting out the oldest when full. If limit <= 0, s is unchanged.

func ChunkSlice

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

ChunkSlice splits a slice into chunks of the specified size. The last chunk may be smaller than chunkSize if the slice length is not divisible by chunkSize.

func ConcatKeepLast

func ConcatKeepLast[T any](chunks [][]T, limit int) []T

ConcatKeepLast flattens chunks, then KeepLast(flat, limit).

func ContainsInSlice

func ContainsInSlice[T comparable](slice []T, value T) bool

ContainsInSlice checks if value exists in slice. Returns true if found, false otherwise.

func ExcludeFromSlice

func ExcludeFromSlice[T comparable](slice, excludeValues []T) []T

ExcludeFromSlice returns a new slice with all values from excludeValues removed from slice not optimized for performance

func KeepLast

func KeepLast[T any](s []T, limit int) []T

KeepLast returns a new slice with the last up to limit elements, or nil if limit <= 0.

func MapSlice

func MapSlice[T, U any](src []T, converter func(T) U) []U

MapSlice applies a converter function to each element of src and returns a new slice. The result slice has the same length as src.

func UniqueComparable

func UniqueComparable[T comparable](slice []T) []T

UniqueComparable returns a new slice containing only unique elements from the input. Uniqueness is determined by ==. Order is preserved (first occurrence kept).

func UniqueSlice

func UniqueSlice[T fmt.Stringer](slice []T) []T

UniqueSlice returns a new slice containing only unique elements from the input. Uniqueness is determined by the String() method of each element. The order of elements is preserved (first occurrence is kept).

Types

This section is empty.

Jump to

Keyboard shortcuts

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