Skip to content

Instantly share code, notes, and snippets.

View ChesterJFGould's full-sized avatar
🏠

Chester Gould ChesterJFGould

🏠
View GitHub Profile
@Splizard
Splizard / Go2GenericType.go
Last active June 10, 2020 16:53
Go 2 generics without syntax changes, 1 new type, 1 new builtin.
//A generics proposal for Go, introducing one new type (generic) and one new builtin function (typeof), no syntax changes.
//Function add takes arguments of any type.
//The return value is automatically inferred based on the arguments, can be inlined by the compiler.
//Both arguments must be the same type and addable or else a compiler error will be raised.
//It's the developer's responsibility to document which types can be passed to this function.
func add(a, b generic) generic {
return a+b
}