Skip to content

Instantly share code, notes, and snippets.

View stevenblenkinsop's full-sized avatar

Steven Blenkinsop stevenblenkinsop

View GitHub Profile
@rogpeppe
rogpeppe / go-generics-mgo-use-case-2.md
Last active September 14, 2018 07:18
Go Contracts as type structs

Go contracts as type structs

Roger Peppe, 2018-09-05

In my previous post, I talked about an issue with a real world use case for contracts - the fact that all type parameters must be mentioned every time a contract is used in a definition. In this post, I introduce an idea for a possible way to fix this.

The most important feature of contracts, in my view,

Revised generics design

Roger Peppe, 2018-09-01

One common response to the new generics design has been that contracts seem a bit too much like interfaces but not the same.

They are indeed very similar if you squint a little. Consider these two definitions:

type IReader interface {

Read([]byte)(int, error)