typeover
curriculum

Curriculum Idioms & ecosystem The small-interface idiom exercise 3 · mcq

The small-interface idiom

Pick the IDIOMATIC interface signature for a function that needs to read bytes from somewhere. (The smallest interface that does this in Go's stdlib has ONE method.)

TypeScript reference
Pick the idiomatic Go translation

About this theme

io.Reader { Read(p []byte) (n int, err error) }. One method. Go interfaces are typically tiny because implicit satisfaction rewards it — small interfaces are easy to satisfy accidentally, which is good. The community phrase: "accept interfaces, return structs." Funcs take the smallest interface they need.