mirror of
https://github.com/tailscale/tailscale.git
synced 2025-10-23 17:18:42 +00:00
types/views: add SliceView.All iterator (#13536)
And convert a all relevant usages. Updates #12912 Signed-off-by: Joe Tsai <joetsai@digital-static.net>
This commit is contained in:
@@ -147,6 +147,17 @@ type SliceView[T ViewCloner[T, V], V StructView[T]] struct {
|
||||
ж []T
|
||||
}
|
||||
|
||||
// All returns an iterator over v.
|
||||
func (v SliceView[T, V]) All() iter.Seq2[int, V] {
|
||||
return func(yield func(int, V) bool) {
|
||||
for i := range v.ж {
|
||||
if !yield(i, v.ж[i].View()) {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MarshalJSON implements json.Marshaler.
|
||||
func (v SliceView[T, V]) MarshalJSON() ([]byte, error) { return json.Marshal(v.ж) }
|
||||
|
||||
|
Reference in New Issue
Block a user