zlacker

[return to "Go(lang): Robust generic functions on slices"]
1. gslall+Ng3[view] [source] 2024-02-24 09:47:08
>>signa1+(OP)
> func Index[S ~[]E, E comparable](s S, v E) int {

After seeing this signature, I think that Go is giving up on it's simpleness principle.

◧◩
2. __s+ct3[view] [source] 2024-02-24 12:55:58
>>gslall+Ng3
Generics can be a bit of an eye sore, but go already had reflection & I recently was mucking around bigquery's internals full of `reflect` having to read through that, & it doesn't even get backed by a type checker

`func Index(s interface{}, v interface{}) int` both has to deal with incompatible types, & the function body is going to be anything but simple

(sure, without generics most people wouldn't even write that `func Index`, but ultimately there's plenty of libraries deep in reflect that'd greatly benefit from generics)

I've also been dealing with temporal.io using interface{} everywhere, got to a point where I wrote typed wrappers using generics to have type checking for signals

[go to top]