refactor(tracker): use go v1.23 style iterators throughout

This commit is contained in:
5684185+vsariola@users.noreply.github.com
2024-10-15 00:01:02 +03:00
parent 2b7ce39069
commit 97e59c5650
7 changed files with 108 additions and 87 deletions

View File

@ -18,7 +18,7 @@ type (
}
AlertPriority int
AlertYieldFunc func(alert Alert)
AlertYieldFunc func(index int, alert Alert) bool
Alerts Model
)
@ -35,9 +35,13 @@ func (m *Model) Alerts() *Alerts { return (*Alerts)(m) }
// Alerts methods
func (m *Alerts) Iterate(yield AlertYieldFunc) {
for _, a := range m.alerts {
yield(a)
func (m *Alerts) Iterate() func(yield func(index int, alert Alert) bool) {
return func(yield func(index int, alert Alert) bool) {
for i, a := range m.alerts {
if !yield(i, a) {
break
}
}
}
}