[generics] gRPC bistream quantization

91 views
Skip to first unread message

Denis Cheremisov

unread,
Jun 17, 2020, 5:00:00 PM6/17/20
to golang-nuts
Another question about generics, a HOWTODO one: I am bored to death writing methods what would send one request and get one response from a gRPC bistream. Decided to try a draft 2 against a generic approach to the task.

My final attempt which I still can't compile: https://go2goplay.golang.org/p/z8XUKua3k-J

Where is the mistake?


andrew....@gmail.com

unread,
Jun 17, 2020, 6:17:08 PM6/17/20
to golang-nuts
Your ReadOne function takes three type parameters: S, Input, and Output. Since S has a constraint, Input and Output also need a constraint (which can just be interface{}).

> func ReadOne(type S Stream(Input, Output), Input interface{}, Output interface{})(...) (...)

I also had to add explicit type arguments to the call to ReadOne since the compiler complains that the type of Output can't be inferred.

> res, err := ReadOne(*dummyStream, int, int)(nil, getStream, 13)


Cheers,
Andrew Ekstedt

Denis Cheremisov

unread,
Jun 17, 2020, 7:29:39 PM6/17/20
to golang-nuts
Thank you
Reply all
Reply to author
Forward
0 new messages