Suppose I have following generic interface:
type Iface[T any] interface {
MyFunc(T)
}
I would like to implement "adapter" or "converter" class, which helps to convert between interfaces of different types. Essentially, it wraps Iface[A] to behave like an Iface[B]:
type Adapter[A any, B any] interface {
Adapt(Iface[A]) Iface[B]
}
So, I can't figure out how to write Adapt function:
type Iface[T any] interface {
MyFunc(T)
}
type Adapter[A any, B any] interface {
Adapt(Iface[A]) Iface[B]
}
type StringToIntAdapter struct {
}
func (StringToIntAdapter) Adapt(Iface[string]) Iface[Int] {
// ???
}
I think I would need to somehow dynamically create a new instance of an interface inside of an adapter. But I can't find any tips out how to do so.