Implemented token splitting as a generator

This commit is contained in:
Eduard Urbach 2025-03-20 00:26:42 +01:00
parent 3ffcfa0084
commit f31ea5e825
Signed by: eduard
GPG key ID: 49226B848C78F6C8
4 changed files with 39 additions and 60 deletions

View file

@ -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.