Documentation ¶
Overview ¶
Package strslices defines various functions useful with slices of string type. The goal is to be as close as possible to https://github.com/golang/go/issues/45955.
Example (Regexp) ¶
a := []string{ "10.0.0.0", "FOO", "1000::1", "fd80::4%eth0", "BAR", "192.168.1.300", "172.12.0.1", "fc00::5000", } re := regexp.MustCompile("^[A-Z]+$") fmt.Println(Filter(nil, a, re.MatchString))
Output: [FOO BAR]
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Equal ¶
Equal reports whether two slices are equal: the same length and all elements equal. If the lengths are different, Equal returns false. Otherwise, the elements are compared in index order, and the comparison stops at the first unequal pair.
func Filter ¶
Filter appends to d each element e of s for which keep(e) returns true. It returns the modified d. d may be s[:0], in which case the kept elements will be stored in the same slice. if the slices overlap in some other way, the results are unspecified. To create a new slice with the filtered results, pass nil for d.
Example (Empty) ¶
s := []string{"FOO", "", "", "BAR", "fd80::8888", ""} fmt.Println(Filter(nil, s, func(s string) bool { return s != "" }))
Output: [FOO BAR fd80::8888]
Types ¶
This section is empty.