Support for generics
Experimental go2go translator is published! https://blog.golang.org/generics-next-step
Hey @tdakkota,
Thanks for creating the issue. For information, I started to work on it on the generics branch but I didn't finish yet. It's really a heavy change and so far the compiler is sometimes panicking without providing useful information so it's not simple.
Anyone who's willing to give it a try can start working from generics (or your own branch, whatever works).
With the upcoming 1.18 go release would this issue pick up some steam?
I think because of lacking of parameterized methods in the current state of generics it would be impossible to migrate this project without major change of API.
@manisenkov But still helpful
I suspect if generics improve the API we'd very much be fine with a breaking API change. Any thoughts on if the current generics Go feature would be enough to make things easier to use?
RxGo is pretty much based on fluent interface (observable.Filter(...).Map(...)) and without type parameters in methods it wouldn't be possible to implement.
The one way is to switch to non-fluent API but it would be not as easy to read
Map(Filter(observable, filterFn), mapFn)
or
ob1 := Filter(observable, filterFn)
ob2 := Map(ob1, filterFn)
(here is an issue for adding type parameters)
when can finish it
Would it be helpful to take inspiration from RxJs and use a pipe function with operators also as functions?
Pipe(
observable,
Filter(fn),
Map(fn),
Reduce(fn)
)
Would it be helpful to take inspiration from RxJs and use a
pipefunction with operators also as functions?Pipe( observable, Filter(fn), Map(fn), Reduce(fn) )
I thought about it, but generics in Go doesn't support variadic number of type arguments. Some kind of solution would be if you have multiple variance for Pipe function for different number of arguments
Pipe2(
observable,
Filter(fn)
)
Pipe3(
observable,
Filter(fn),
Map(fn),
)
Pipe4(
observable,
Filter(fn),
Map(fn),
Reduce(fn),
)
// etc...
An example of what the above could look like: https://go.dev/play/p/AJwmCH2iIA-