I'm trying out go generics in 1.18beta2 and I'm trying to write an abstraction layer for key/value store, boltdb. This is what I'm trying to achieve with it.
type Reader interface {
Read(bucket []byte, k ...[]byte) ([][]byte, error)
ReadDoc[V Unmarshaler](bucket []byte, factory func() (V, error), k ...[]byte) ([]V, error)
}
type Unmarshaler interface {
UnmarshalKV(v []byte) error
}
So that I can provide it a factory to create the type when it finds a key/value, unmarshal the data into it and return back a slice of that specific type. Only I get "interface method must have no type parameters" from the compiler. Why are't type parameters allowed in interfaces? Is supporting this planned? This has crushed my dreams... Would have been perfect. It does however work out of interface.
MyTestDocs, err := boltdb.ReadDoc([]byte("bucket"), NewTestDocument, []byte("key1"), []byte("key2")
where the implementer of the interface is the database – Stubborn