There isn’t a standard library or built-in function that does both a 
comparison and less operation.

For best performance you would write it for your type. For best generality 
you would write a library function that takes two interface{} values and 
converts them to the comparable types that work with == and < with an 
exhaustive interface type switch.

The general case with interface{} would be a good community library, but I 
don’t think it exists. Writing it for your type is straightforward.

type X int

func (x X) Cmp(y X) int {
    if x == y {
        return 0
    } else if x < y {
        return -1
    } else {
        return 1
    }
}

// or a function instead of method
func CmpX(x, y X) int {

}

Matt

On Sunday, January 21, 2018 at 7:42:49 AM UTC-6, Peng Yu wrote:
>
> Hi, cmp() in python can return three values -1, 0, 1. Is there a 
> comparison function in golang that also return three values? Thanks. 
>
> https://docs.python.org/2/library/functions.html#cmp 
>
> -- 
> Regards, 
> Peng 
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to