package sliceext

import "github.com/go-playground/pkg/v5/slice"

Index

Functions

func Filter

func Filter[T any](slice []T, fn func(v T) bool) []T

Filter filters out the elements specified by the function.

This shuffles and returns the retained values of the slice.

func Map

func Map[T, U any](slice []T, init U, fn func(accum U, v T) U) U

Map maps a slice of []T -> []U using the map function.

func Reduce

func Reduce[T any](slice []T, fn func(accum T, current T) T) optionext.Option[T]

Reduce reduces the elements to a single one, by repeatedly applying a reducing function.

func Retain

func Retain[T any](slice []T, fn func(v T) bool) []T

Retain retains only the elements specified by the function.

This shuffles and returns the retained values of the slice.

func Reverse

func Reverse[T any](slice []T)

Reverse reverses the slice contents.

func Sort

func Sort[T any](slice []T, less func(i T, j T) bool)

Sort sorts the sliceWrapper x given the provided less function.

The sort is not guaranteed to be stable: equal elements may be reversed from their original order.

For a stable sort, use SortStable.

func SortStable

func SortStable[T any](slice []T, less func(i T, j T) bool)

SortStable sorts the sliceWrapper x using the provided less function, keeping equal elements in their original order.

Source Files

slice.go

Version
v5.24.0
Published
Jan 21, 2024
Platform
darwin/amd64
Imports
2 packages
Last checked
41 minutes ago

Tools for package owners.