clipperhouse / gen

Type-driven code generation for Go
http://clipperhouse.com/gen/overview/
Other
1.43k stars 90 forks source link

Compare #83

Open awalterschulze opened 9 years ago

awalterschulze commented 9 years ago

Hi

Would you be interested in having a compare typewriter?

This would basically just compare each field for a type from top to bottom. When a field is found with a compare != 0 then that value is returned.

Here is some example generated code.

func (this *MyType) Compare(that *MyType) int {
  if this.Field1 != that.Field1 {
    if this.Field1 < that.Field1 {
      return -1
    }
    return 1
  }
  if c := bytes.Compare(this.Field2, that.Field2); c != 0 {
    return c
  }
  if c := this.Field3.Compare(that.Field3); c != 0 {
    return c
  }
  return 0
}

Would you be interested in such a pull request?