good icon indicating copy to clipboard operation
good copied to clipboard

Multisignatures

Open kirillDanshin opened this issue 9 years ago • 2 comments

Let's say we have this struct:

type SomeStore struct {
    b int
    c string
    d float64
}

User should be able to define functions like:

func Store(n int) *SomeStore {
    return &SomeStore{b: n}
}
func Store(c string) *SomeStore {
    return &SomeStore{c: c}
}
func Store(d float64) *SomeStore {
    return &SomeStore{d: d}
}

And methods:

func (s *SomeStore) Set(n int) {
    s.b = n
}
func (s *SomeStore) Set(c string) {
    s.c = c
}
func (s *SomeStore) Set(d float64) {
    s.d = d
}

And more on methods:

func (a *A) Set(anotherA *A) {
    a.b = anotherA.b
    a.c = anotherA.c
    a.d = anotherA.d
}
func (a *A) Set(c string) {
    a.Set(15<<2, c)
}
func (a *A) Set(c int, d string) {
    a.b = c
    a.c = d
}

kirillDanshin avatar Dec 14 '16 07:12 kirillDanshin

I've used this in my Java days.

finally I found it is more convenience to have clear methods name

onokonem avatar Dec 14 '16 09:12 onokonem

Multidispatch for the win!

alexclear avatar Dec 14 '16 13:12 alexclear