Skip to content

Instantly share code, notes, and snippets.

@Pygmalion69
Created February 29, 2020 16:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Pygmalion69/7109648716dda9e4d82d6e656c73ba41 to your computer and use it in GitHub Desktop.
Save Pygmalion69/7109648716dda9e4d82d6e656c73ba41 to your computer and use it in GitHub Desktop.
A Tour of Go - Exercise: Reader
// https://tour.golang.org/methods/22
package main
import "golang.org/x/tour/reader"
type MyReader struct{}
func (r MyReader) Read(b []byte) (int, error) {
for i := range b {
b[i] = 65
}
return len(b), nil
}
/* Shortest solution that validates
func (r MyReader) Read(b []byte) (int, error) {
b[0] = 65
return 1, nil
}
*/
func main() {
reader.Validate(MyReader{})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment