On Wednesday, June 17, 2020 at 2:00:00 PM UTC-7, Denis Cheremisov wrote:
>
> 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?
>
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)
https://go2goplay.golang.org/p/RQEyhRRQb0p
Cheers,
Andrew Ekstedt
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/golang-nuts/7f8dee1e-16e3-4a79-9295-c4ed89b4232co%40googlegroups.com.