RxGo icon indicating copy to clipboard operation
RxGo copied to clipboard

Support for generics

Open ghost opened this issue 5 years ago • 11 comments

Experimental go2go translator is published! https://blog.golang.org/generics-next-step

ghost avatar Jun 26 '20 16:06 ghost

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).

teivah avatar Jun 26 '20 16:06 teivah

With the upcoming 1.18 go release would this issue pick up some steam?

czras avatar Feb 13 '22 21:02 czras

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 avatar Mar 13 '22 00:03 manisenkov

@manisenkov But still helpful

aak1247 avatar Mar 29 '22 10:03 aak1247

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?

evanmoran avatar Apr 12 '22 22:04 evanmoran

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)

manisenkov avatar May 10 '22 13:05 manisenkov

when can finish it

simake2017 avatar Jul 04 '22 07:07 simake2017

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)
)

ianldgs avatar Jul 04 '22 08:07 ianldgs

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)
)

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...

manisenkov avatar Jul 04 '22 11:07 manisenkov

An example of what the above could look like: https://go.dev/play/p/AJwmCH2iIA-

ianldgs avatar Aug 08 '22 10:08 ianldgs