Skip to content

Instantly share code, notes, and snippets.

@sahajre
Created August 1, 2019 07:55
Show Gist options
  • Save sahajre/71f08b14624daf426c8b740bbae6e430 to your computer and use it in GitHub Desktop.
Save sahajre/71f08b14624daf426c8b740bbae6e430 to your computer and use it in GitHub Desktop.
package main
import "fmt"
func getGreetingByteSeq() func() (byte, bool) {
i := 0
s := "Hello, 世界"
return func() (byte, bool) {
i++
return s[i-1], i == len(s)
}
}
func main() {
getNextByte := getGreetingByteSeq()
s := make([]byte, 0)
b, last := getNextByte()
for {
if last {
s = append(s, b)
break
} else {
s = append(s, b)
b, last = getNextByte()
}
}
fmt.Println(string(s))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment