Skip to content

添加迭代器示例代码 & 更新文档 #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func main() {

## 3.5 迭代器模式

`CycleString`有一个迭代器模式的实现`CycleStringIterator`,通过`Iterator`方法来获取:
`CycleString`有两个迭代器模式的实现`CycleStringByteIterator`和`CycleStringRuneIterator`,通过`ByteIterator`和`RuneIterator`方法来获取:

```go
package main
Expand All @@ -129,15 +129,16 @@ import (
func main() {

cycleString := cycle_string.NewCycleString("CC11001100")
iterator := cycleString.Iterator()
iterator := cycleString.RuneIterator()

fmt.Println(string(iterator.NextN(3)))

for iterator.Next() {
fmt.Println(string(iterator.Value()))
time.Sleep(time.Millisecond * 100)
}
// Output:
// C
// C
// 1
// CC1
// 1
// 0
// 0
Expand Down
9 changes: 5 additions & 4 deletions examples/iterator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@ import (
func main() {

cycleString := cycle_string.NewCycleString("CC11001100")
iterator := cycleString.Iterator()
iterator := cycleString.RuneIterator()

fmt.Println(string(iterator.NextN(3)))

for iterator.Next() {
fmt.Println(string(iterator.Value()))
time.Sleep(time.Millisecond * 100)
}
// Output:
// C
// C
// 1
// CC1
// 1
// 0
// 0
Expand Down