-
-
Notifications
You must be signed in to change notification settings - Fork 88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Type transformations in Map #37
Comments
I fully agree with this point. It would be very nice to be able to transform any |
I tried to brainstorm a lot on this but most of the options (something that exists in other FP languages) are a bit constrained with Golang since it is not allowing type parameters on methods. But I was able to come up with a workaround where we are able to exploit the functional aspects using the Functions in golang.
There are two downsides which I see to this:
Please share your thoughts on this. |
The mappable interface here can also be simplified, since we are using the pattern matching on the basis of types, and hence the class methods can be used directly here. |
Unfortunately this seems like a limitation of Go itself. If I wrote for example type Action[T any] func() (T, error)
func [T, U any] (a Action[T]) FlatMap(f func(T) Action[U]) Action[U] {
// ...
} It doesn't compile because you can't declare generic type parameters on a method. func FlatMap[T,U any] (a Action[T], f func(T) Action[U]) Action[U] {
// ...
} and it compiles and works as expected, but what you lose is the syntactic convenience of being able to chain these like a method call or infix operation which avoids a bunch of deeply nested parentheses and makes the code nice and readable. |
Generally the map function supports type transformations from
T[A] => T[B]
which is used the most in all practical use cases.While the library supports mapping, but its applicability is very limited due to this limitations.
I believe this is majorly because Golang does not support type arguments on methods.
Any means to bypass this and get a more practical mappers?
The text was updated successfully, but these errors were encountered: