Hello,

I would like to write a  type constraint which matches types like the 
following:

type v1 int

func (obj v1) Add(other v1) v1 {
    return obj + other
}

type v2 string

func (obj v2) Add(other v2) v2 {
    return obj + other
}

This should match anything with an Add() method which can add another item 
of the same type.  I want to be able to write a function like the following:

func Double[Adder ...???...](x Adder) Adder {
    return x.Add(x)
}

My best attempts is https://go.dev/play/p/R0WLqSq9dys , but this doesn't 
quite work.  What is the correct type constraint to use?

Many thanks,
Jochen

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/5d8fcc25-2174-4c1d-a325-29111932fe6dn%40googlegroups.com.

Reply via email to