contains

package
v2.3.1 Latest Latest
Warning

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

Go to latest
Published: May 20, 2022 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package contains checks if a value is included in a slice of values.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Int

func Int(list []int, value int) bool

Int checks if a slice of integers contains a certain int value.

Example
package main

import (
	"fmt"

	"github.com/fastbill/go-tiny-helpers/v2/contains"
)

func main() {
	input := []int{-1, 1, 2, 3}
	fmt.Println(contains.Int(input, 2))
	fmt.Println(contains.Int(input, 100))

}
Output:

true
false

func Int64

func Int64(list []int64, value int64) bool

Int64 checks if a slice of int64 values contains a certain int64 value.

Example
package main

import (
	"fmt"

	"github.com/fastbill/go-tiny-helpers/v2/contains"
)

func main() {
	input := []int64{-1, 1, 2, 3}
	fmt.Println(contains.Int64(input, 2))
	fmt.Println(contains.Int64(input, 100))

}
Output:

true
false

func String

func String(list []string, value string) bool

String checks if a slice of strings contains a certain string value. The check is case sensitive, "Go" and "go" will not match.

Example
package main

import (
	"fmt"

	"github.com/fastbill/go-tiny-helpers/v2/contains"
)

func main() {
	input := []string{"a", "b", "c"}
	fmt.Println(contains.String(input, "b"))
	fmt.Println(contains.String(input, "C"))

}
Output:

true
false

func StringCaseInsensitive added in v2.2.0

func StringCaseInsensitive(list []string, value string) bool

StringCaseInsensitive checks if a slice of strings contains a certain string value. The check is case insensitive, "Go" and "go" will be counted as a match. See https://pkg.go.dev/strings#EqualFold for details.

Example
package main

import (
	"fmt"

	"github.com/fastbill/go-tiny-helpers/v2/contains"
)

func main() {
	input := []string{"APPLE", "banana", "CasheW"}
	fmt.Println(contains.StringCaseInsensitive(input, "apple"))
	fmt.Println(contains.StringCaseInsensitive(input, "BAnana"))
	fmt.Println(contains.StringCaseInsensitive(input, "cashew"))
	fmt.Println(contains.StringCaseInsensitive(input, "app"))

}
Output:

true
true
true
false

func Uint64

func Uint64(list []uint64, value uint64) bool

Uint64 checks if a slice of uint64 values contains a certain uint64 value.

Example
package main

import (
	"fmt"

	"github.com/fastbill/go-tiny-helpers/v2/contains"
)

func main() {
	input := []uint64{1, 2, 3}
	fmt.Println(contains.Uint64(input, 2))
	fmt.Println(contains.Uint64(input, 100))

}
Output:

true
false

Types

This section is empty.

Jump to

Keyboard shortcuts

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