slicex

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package slicex provides generic functional utilities for slices.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Filter

func Filter[T any](items []T, pred func(T) bool) []T

Filter returns a new slice containing only the elements of items for which pred returns true.

func Map

func Map[T any, R any](items []T, fn func(T) R) []R

Map transforms each element in items using the given transform function.

func SplitAndTrim

func SplitAndTrim(input, sep string) []string

SplitAndTrim splits input by sep, trims leading and trailing whitespace from each substring, and returns a slice of non-empty substrings. Returns nil if input is empty.

func Unique

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

Unique returns a new slice containing only unique elements from items, preserving the order of first appearance.

func UniqueBy

func UniqueBy[T any, K comparable](items []T, keyFn func(T) K) []T

UniqueBy returns a new slice containing only the elements of items with unique keys determined by keyFn, preserving the order of first appearance.

Types

This section is empty.

Jump to

Keyboard shortcuts

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