slices

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2023 License: Apache-2.0, GPL-2.0, GPL-3.0-or-later, + 1 more Imports: 2 Imported by: 0

Documentation

Overview

Package slices implements generic (type-parameterized) utilities for working with simple Go slices.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Contains

func Contains[T comparable](needle T, haystack []T) bool

func Max

func Max[T constraints.Ordered](a T, rest ...T) T

func Min

func Min[T constraints.Ordered](a T, rest ...T) T

func RemoveAll

func RemoveAll[T comparable](haystack []T, needle T) []T

func RemoveAllFunc

func RemoveAllFunc[T any](haystack []T, f func(T) bool) []T

func Reverse

func Reverse[T any](slice []T)
func Search[T any](slice []T, fn func(T) int) (int, bool)

Search searches the slice for a value for which `fn(slice[i]) = 0`.

: + + + 0 0 0 - - -
:       ^ ^ ^
:       any of

You can conceptualize `fn` as subtraction:

func(straw T) int {
    return needle - straw
}

func SearchHighest

func SearchHighest[T any](slice []T, fn func(T) int) (int, bool)

SearchHighest searches the slice for the right-most value for which `fn(slice[i]) = 0`.

: + + + 0 0 0 - - -
:           ^

You can conceptualize `fn` as subtraction:

func(straw T) int {
    return needle - straw
}

func SearchLowest

func SearchLowest[T any](slice []T, fn func(T) int) (int, bool)

SearchLowest searches the slice for the left-most value for which `fn(slice[i]) = 0`.

: + + + 0 0 0 - - -
:       ^

You can conceptualize `fn` as subtraction:

func(straw T) int {
    return needle - straw
}

func Sort

func Sort[T constraints.Ordered](slice []T)

Types

This section is empty.

Jump to

Keyboard shortcuts

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