slicehelper

package module
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2024 License: MIT Imports: 5 Imported by: 1

README

slicehelper

Go Reference

Helpers for Go's slice.

Documentation

Overview

Package slicehelper contains slice-related helpers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Map added in v0.5.0

func Map[S ~[]Es, R ~[]Er, Es, Er any](s S, m func(Es) Er) R

Map projects the elements of 's' into a new slice.

func RemoveInPlace

func RemoveInPlace[S ~[]E, E any](s S, idx int) (S, error)

RemoveInPlace removes in place from 's' the element at the specified index.

func ReverseNew

func ReverseNew[S ~[]E, E any](s S) S

ReverseNew returns new slice containing the reversed elements of 's'. The initial slice remains unchanged. If 's' is nil, nil is returned.

func SortDesc added in v0.2.0

func SortDesc[S ~[]E, E cmp.Ordered](x S)

SortDesc is like slices.Sort but sorts a slice in descending order.

func Split

func Split(len, n int) ([]int, error)

Split splits a sequence of ints [0..'len'-1] (indexes of a slice with length 'len') into 'n' as equal as possible integer parts. 'len' and 'n' must be greater than 1. 'len' must not be less than 'n'. The result contains start indexes of the parts and 'len', so each consecutive pair of the result's elements may be used as 'low' and 'high' indices for subslicing (see TestSplit for example). Function is intended for splitting a slice for (parallel) processing of the parts.

func Trim added in v0.4.0

func Trim[S ~[]E, E any](s S, f func(E) bool) S

Trim removes all leading and trailing elements from 's' that satisfy 'f'. If 's' is nil or empty or 'f' is nil, 's' is returned.

func TrimEnd added in v0.4.0

func TrimEnd[S ~[]E, E any](s S, f func(E) bool) S

TrimEnd removes all the elements from 's' that satisfy 'f'. If 's' is nil or empty or 'f' is nil, 's' is returned.

func TrimStart added in v0.4.0

func TrimStart[S ~[]E, E any](s S, f func(E) bool) S

TrimStart removes all the leading elements from 's' that satisfy 'f'. If 's' is nil or empty or 'f' is nil, 's' is returned.

Types

This section is empty.

Jump to

Keyboard shortcuts

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