Implement a Reader type that emits an infinite stream of the ASCII character 'A'.
I don't understand the question, how to emit character 'A'? into which variable should I set that character?
Here's what I tried:
package main
import "code.google.com/p/go-tour/reader"
type MyReader struct{}
// TODO: Add a Read([]byte) (int, error) method to MyReader.
func (m MyReader) Read(b []byte) (i int, e error) {
b = append(b,'A') // this is wrong..
return 1, nil // this is also wrong..
}
func main() {
reader.Validate(MyReader{}) // what did this function expect?
}
Ah I understand XD
I think it would be better to say: "rewrite all values in []byte
into 'A'
s"
package main
import "code.google.com/p/go-tour/reader"
type MyReader struct{}
// TODO: Add a Read([]byte) (int, error) method to MyReader.
func (m MyReader) Read(b []byte) (i int, e error) {
for x := range b {
b[x] = 'A'
}
return len(b), nil
}
func main() {
reader.Validate(MyReader{})
}