Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12111

Is there a simpler way to write this logic in Go?

$
0
0

I have a structure in Go which looks like this:

type A struct {    Name string    Type string    Time string}

And I want to write a less function to compare two struct A, such as

func (s A) less(other A) bool {    if s.Name < other.Name {        return True    }    if other.Name < s.Name {        return False    }    if s.Type < other.Type {        return True    }    if other.Type < s.Type {        return False    }    return s.Time < other.Time}

I wonder if there is a better way/a simpler way to write this logic? Thanks!


Viewing all articles
Browse latest Browse all 12111

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>