gitlab.com/evatix-go/core@v1.3.55/anycmp/Cmp.go (about)

     1  package anycmp
     2  
     3  import (
     4  	"gitlab.com/evatix-go/core/corecomparator"
     5  	"gitlab.com/evatix-go/core/isany"
     6  )
     7  
     8  func Cmp(left, right interface{}) corecomparator.Compare {
     9  	if left == right {
    10  		return corecomparator.Equal
    11  	}
    12  
    13  	if left == nil && right == nil {
    14  		return corecomparator.Equal
    15  	}
    16  
    17  	if left == nil || right == nil {
    18  		return corecomparator.NotEqual
    19  	}
    20  
    21  	isLeftNull, isRightNull := isany.NullLeftRight(left, right)
    22  	isBothEqual := isLeftNull == isRightNull
    23  
    24  	if isLeftNull && isBothEqual {
    25  		// both null
    26  		return corecomparator.Equal
    27  	} else if !isBothEqual && isLeftNull || isRightNull {
    28  		// any null but the other is not
    29  		return corecomparator.NotEqual
    30  	}
    31  
    32  	return corecomparator.Inconclusive
    33  }