Implemented token splitting as a generator
This commit is contained in:
parent
3ffcfa0084
commit
f31ea5e825
4 changed files with 39 additions and 60 deletions
|
@ -30,9 +30,9 @@ func (list List) LastIndexKind(kind Kind) int {
|
|||
}
|
||||
|
||||
// Split calls the callback function on each set of tokens in a comma separated list.
|
||||
func (list List) Split(call func(List) error) error {
|
||||
func (list List) Split(yield func(List) bool) {
|
||||
if len(list) == 0 {
|
||||
return nil
|
||||
return
|
||||
}
|
||||
|
||||
start := 0
|
||||
|
@ -52,18 +52,16 @@ func (list List) Split(call func(List) error) error {
|
|||
}
|
||||
|
||||
parameter := list[start:i]
|
||||
err := call(parameter)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
if !yield(parameter) {
|
||||
return
|
||||
}
|
||||
|
||||
start = i + 1
|
||||
}
|
||||
}
|
||||
|
||||
parameter := list[start:]
|
||||
return call(parameter)
|
||||
yield(list[start:])
|
||||
}
|
||||
|
||||
// Text returns the concatenated token text.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue