Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I think the code you linked shows exactly why generics are needed for these kinds of methods. By introducing a single generic, you could reduce it from 500 lines to 20, and make it work for all types, not just the built-in ones. It would also remove the need to have different method names.

I think that makes it less complex, as the developer doesn't need to think about the exact underlying type of the array when calling Take (which is irrelevant to its implementation).



>> By introducing a single generic, you could reduce it from 500 lines to 20

No one is writing 500 lines of code - just as when you use the generics syntax you don’t write the code that is generated by the compiler in response.

You could save about 10 lines, specifically these 10:

https://github.com/logic-building/functional-go/blob/master/...

You would still need the comparable ~40 lines of “generic” code:

https://github.com/logic-building/functional-go/blob/master/...




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: