-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from lestrrat-go/remove-iter
Remove iter
- Loading branch information
Showing
2 changed files
with
35 additions
and
70 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,16 @@ | ||
package trie | ||
|
||
import ( | ||
"iter" | ||
) | ||
type stringTokenizer struct{} | ||
|
||
func (stringTokenizer) Tokenize(s string) ([]rune, error) { | ||
var list []rune | ||
for _, r := range s { | ||
list = append(list, r) | ||
} | ||
return list, nil | ||
} | ||
|
||
// String returns a Tokenizer that tokenizes a string into individual runes. | ||
func String() Tokenizer[string, rune] { | ||
return TokenizeFunc[string, rune](func(s string) (iter.Seq[rune], error) { | ||
return func(yield func(rune) bool) { | ||
for _, r := range s { | ||
if !yield(r) { | ||
break | ||
} | ||
} | ||
}, nil | ||
}) | ||
return stringTokenizer{} | ||
} |
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