Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ContainsString ¶
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 ¶
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.
Click to show internal directories.
Click to hide internal directories.