slice

package
v4.16.3 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2023 License: Apache-2.0 Imports: 1 Imported by: 3

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContainsString

func ContainsString(s string, slice []string, modifier func(s string) string) bool

ContainsString checks if a given slice of strings contains the provided string. If a modifier func is provided, it is called with the slice item before the comparation.

     haystack := []string{"one", "Two", "Three"}
	if slice.ContainsString(haystack, "two", strings.ToLower) {
		// Do thing
	}

func ContainsStringEqualFold

func ContainsStringEqualFold(s string, slice []string) bool

ContainsStringEqualFold checks if a given slice of strings contains the provided string as ignore the cases.

 haystack := []string{"aa", "bb", "Cc"}
	if slice.ContainsStringEqualFold(haystack, "cC") {
		// Do thing
	}

func Remove added in v4.16.3

func Remove[T comparable](slice []T, i, j int) []T

Remove removes the given index range from the given slice, preserving element order. It is the safer version of slices.Delete() as it will not panic on invalid slice ranges. Nil and empty slices are also safe. Remove modifies the contents of the given slice and performs no allocations or copies.

Example
package main

import (
	"fmt"

	"github.com/mailgun/holster/v4/slice"
)

func main() {
	s := []string{"1", "2", "3"}
	i := []int{1, 2, 3}

	fmt.Println(slice.Remove(s, 0, 2))
	fmt.Println(slice.Remove(i, 1, 2))
}
Output:
[3]
[1 3]

Types

This section is empty.

Jump to

Keyboard shortcuts

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