compare

package
v2.2.4 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2023 License: MIT Imports: 5 Imported by: 2

Documentation

Overview

Package compare provides a lightweight comparison function on any type. reference: https://github.com/stretchr/testify

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Equal

func Equal(left, right any) bool

Equal checks if two values are equal or not. (check both type and value) Play: https://go.dev/play/p/wmVxR-to4lz

Example
result1 := Equal(1, 1)
result2 := Equal("1", "1")
result3 := Equal([]int{1, 2, 3}, []int{1, 2, 3})
result4 := Equal(map[int]string{1: "a", 2: "b"}, map[int]string{1: "a", 2: "b"})

result5 := Equal(1, "1")
result6 := Equal(1, int64(1))
result7 := Equal([]int{1, 2}, []int{1, 2, 3})

fmt.Println(result1)
fmt.Println(result2)
fmt.Println(result3)
fmt.Println(result4)
fmt.Println(result5)
fmt.Println(result6)
fmt.Println(result7)
Output:

true
true
true
true
false
false
false

func EqualValue

func EqualValue(left, right any) bool

EqualValue checks if two values are equal or not. (check value only) Play: https://go.dev/play/p/fxnna_LLD9u

Example
result1 := EqualValue(1, 1)
result2 := EqualValue(int(1), int64(1))
result3 := EqualValue(1, "1")
result4 := EqualValue(1, "2")

fmt.Println(result1)
fmt.Println(result2)
fmt.Println(result3)
fmt.Println(result4)
Output:

true
true
true
false

func GreaterOrEqual

func GreaterOrEqual(left, right any) bool

GreaterOrEqual checks if value `left` greater than or equal to value `right`. Play: https://go.dev/play/p/vx8mP0U8DFk

Example
result1 := GreaterOrEqual(1, 1)
result2 := GreaterOrEqual(2.2, 1.1)
result3 := GreaterOrEqual("b", "b")

time1 := time.Now()
time2 := time1.Add(time.Second)
result4 := GreaterOrEqual(time2, time1)

result5 := GreaterOrEqual(1, 2)
result6 := GreaterOrEqual(int64(2), 1)
result7 := GreaterOrEqual("b", "c")

fmt.Println(result1)
fmt.Println(result2)
fmt.Println(result3)
fmt.Println(result4)
fmt.Println(result5)
fmt.Println(result6)
fmt.Println(result7)
Output:

true
true
true
true
false
false
false

func GreaterThan

func GreaterThan(left, right any) bool

GreaterThan checks if value `left` greater than value `right`. Play: https://go.dev/play/p/9-NYDFZmIMp

Example
result1 := GreaterThan(2, 1)
result2 := GreaterThan(2.2, 1.1)
result3 := GreaterThan("b", "a")

time1 := time.Now()
time2 := time1.Add(time.Second)
result4 := GreaterThan(time2, time1)

result5 := GreaterThan(1, 2)
result6 := GreaterThan(int64(2), 1)
result7 := GreaterThan("b", "c")

fmt.Println(result1)
fmt.Println(result2)
fmt.Println(result3)
fmt.Println(result4)
fmt.Println(result5)
fmt.Println(result6)
fmt.Println(result7)
Output:

true
true
true
true
false
false
false

func LessOrEqual

func LessOrEqual(left, right any) bool

LessOrEqual checks if value `left` less than or equal to value `right`. Play: https://go.dev/play/p/e4T_scwoQzp

Example
result1 := LessOrEqual(1, 1)
result2 := LessOrEqual(1.1, 2.2)
result3 := LessOrEqual("a", "b")

time1 := time.Now()
time2 := time1.Add(time.Second)
result4 := LessOrEqual(time1, time2)

result5 := LessOrEqual(2, 1)
result6 := LessOrEqual(1, int64(2))

fmt.Println(result1)
fmt.Println(result2)
fmt.Println(result3)
fmt.Println(result4)
fmt.Println(result5)
fmt.Println(result6)
Output:

true
true
true
true
false
false

func LessThan

func LessThan(left, right any) bool

LessThan checks if value `left` less than value `right`. Play: https://go.dev/play/p/cYh7FQQj0ne

Example
result1 := LessThan(1, 2)
result2 := LessThan(1.1, 2.2)
result3 := LessThan("a", "b")

time1 := time.Now()
time2 := time1.Add(time.Second)
result4 := LessThan(time1, time2)

result5 := LessThan(2, 1)
result6 := LessThan(1, int64(2))

fmt.Println(result1)
fmt.Println(result2)
fmt.Println(result3)
fmt.Println(result4)
fmt.Println(result5)
fmt.Println(result6)
Output:

true
true
true
true
false
false

Types

This section is empty.

Jump to

Keyboard shortcuts

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