mirror of
https://github.com/go-task/task.git
synced 2025-06-23 00:38:19 +02:00
feat: iterators (#1798)
* feat: update to github.com/elliotchance/orderedmap/v3 * refactor: better sort package * feat: iterators * chore: remove unnecessary code
This commit is contained in:
@ -1,7 +1,9 @@
|
||||
package ast
|
||||
|
||||
import (
|
||||
"github.com/elliotchance/orderedmap/v2"
|
||||
"iter"
|
||||
|
||||
"github.com/elliotchance/orderedmap/v3"
|
||||
"gopkg.in/yaml.v3"
|
||||
|
||||
"github.com/go-task/task/v3/errors"
|
||||
@ -48,16 +50,28 @@ func (matrix *Matrix) Set(key string, value []any) bool {
|
||||
return matrix.om.Set(key, value)
|
||||
}
|
||||
|
||||
func (matrix *Matrix) Range(f func(k string, v []any) error) error {
|
||||
// All returns an iterator that loops over all task key-value pairs.
|
||||
func (matrix *Matrix) All() iter.Seq2[string, []any] {
|
||||
if matrix == nil || matrix.om == nil {
|
||||
return nil
|
||||
return func(yield func(string, []any) bool) {}
|
||||
}
|
||||
for pair := matrix.om.Front(); pair != nil; pair = pair.Next() {
|
||||
if err := f(pair.Key, pair.Value); err != nil {
|
||||
return err
|
||||
}
|
||||
return matrix.om.AllFromFront()
|
||||
}
|
||||
|
||||
// Keys returns an iterator that loops over all task keys.
|
||||
func (matrix *Matrix) Keys() iter.Seq[string] {
|
||||
if matrix == nil || matrix.om == nil {
|
||||
return func(yield func(string) bool) {}
|
||||
}
|
||||
return nil
|
||||
return matrix.om.Keys()
|
||||
}
|
||||
|
||||
// Values returns an iterator that loops over all task values.
|
||||
func (matrix *Matrix) Values() iter.Seq[[]any] {
|
||||
if matrix == nil || matrix.om == nil {
|
||||
return func(yield func([]any) bool) {}
|
||||
}
|
||||
return matrix.om.Values()
|
||||
}
|
||||
|
||||
func (matrix *Matrix) DeepCopy() *Matrix {
|
||||
|
Reference in New Issue
Block a user