Documentation
¶
Overview ¶
Example ¶
package main
import (
"fmt"
"github.com/jeremmfr/go-utils/basiccheck"
)
func main() {
input1 := []string{"foo", "bar"}
input2 := []string{"bar", "foo"}
if basiccheck.SimilarSlice(input1, input2) {
fmt.Printf("%v =~ %v", input1, input2)
} else {
fmt.Printf("%v != %v", input1, input2)
}
}
Output: [foo bar] =~ [bar foo]
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AllInSliceWith ¶ added in v0.5.0
AllInSliceWith check if all elements in a slice return true with the function 'valid' passed in arguments.
If 'valid' is nil, return true.
Example ¶
package main
import (
"fmt"
"strings"
"github.com/jeremmfr/go-utils/basiccheck"
)
func main() {
input := []string{"boo", "bar", "baz"}
if basiccheck.AllInSliceWith(input, func(s string) bool {
return strings.HasPrefix(s, "b")
}) {
fmt.Printf("all of %v has prefix 'b'", input)
} else {
fmt.Printf("one of %v has not prefix 'b'", input)
}
}
Output: all of [boo bar baz] has prefix 'b'
func SimilarSlice ¶ added in v0.11.0
func SimilarSlice[T comparable](a, b []T) bool
SimilarSlice check if two slice is Similar: same length, same element (not necessarily in same order).
Elements that appear multiple times must appear same times between the two slices.
Example ¶
package main
import (
"fmt"
"github.com/jeremmfr/go-utils/basiccheck"
)
func main() {
a := []string{"foo", "bar", "baz"}
b := []string{"baz", "foo", "bar"}
if basiccheck.SimilarSlice(a, b) {
fmt.Print("a == b")
} else {
fmt.Print("a != b")
}
}
Output: a == b
func StringHasOneOfPrefixes ¶ added in v0.2.0
StringHasOneOfPrefixes check if string has one of prefix list.
func StringHasOneOfSuffixes ¶ added in v0.10.0
StringHasOneOfSuffixes check if string has one of suffix list.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.