Vladimir Vivien Profile picture
I build 🏗 software • Author (Programming in Go https://t.co/qOaDuOZBc3) • RISC-V and ML/AI fanboy

Aug 23, 2020, 7 tweets

The #golang proposal to introduce generic functions and types (via parametric polymorphism) has been evolving nicely. This 🧵 summarizes what the latest is:

- [] sqr brackets to be used for type param
- type param must have a constraint
- constraint `any` will be new keyword

Use type constraints to define the set of types that can satisfy type arguments

Example: defining and using a generic function

Types can be constrained by behavior by specifying a list of methods that must be implemented by the type argument

Constraints can be more restrictive by specifying both a type list and a method list

Beside functions, types can be defined as being parametric

Example: using a generic type

Share this Scrolly Tale with your friends.

A Scrolly Tale is a new way to read Twitter threads with a more visually immersive experience.
Discover more beautiful Scrolly Tales like this.

Keep scrolling