Created
August 1, 2019 07:55
-
-
Save sahajre/71f08b14624daf426c8b740bbae6e430 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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