Help us shape the future of Go! Take the 2026 Go Developer Survey

slicehelpers

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: May 24, 2026 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](s []T, n int) [][]T

Chunk splits the slice s into n number of chunks.

func Partition added in v0.5.0

func Partition[T any](s []T, size int) [][]T

Partition partitions s into slices of size size.

Types

type Stack added in v0.6.0

type Stack[T any] interface {
	// Push adds an element to the stack.
	Push(v T)
	// Pop removes and returns the top element of the stack.
	Pop() T
	// Peek returns the top element of the stack.
	Peek() T
	// Drain removes all elements from the stack and returns them.
	Drain() []T
	// Len returns the number of elements in the stack.
	Len() int
}

Stack is a stack data structure.

func NewStack added in v0.6.0

func NewStack[T any](conf StackConfig) Stack[T]

NewStack returns a new Stack.

type StackConfig added in v0.6.0

type StackConfig struct {
	// ThreadSafe indicates if the stack should be thread safe.
	ThreadSafe bool
}

StackConfig holds the configuration for a Stack.

Jump to

Keyboard shortcuts

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