Skip to content

Commit

Permalink
Enable filtering of EventLists
Browse files Browse the repository at this point in the history
Signed-off-by: Matej Pavlovic <[email protected]>
  • Loading branch information
matejpavlovic committed Nov 28, 2023
1 parent 5b01ac9 commit e100175
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions pkg/events/eventlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,20 @@ func (el *EventList) Slice() []*eventpb.Event {
return events
}

// Filter returns a new event list containing only those items for which predicate returns true.
func (el *EventList) Filter(predicate func(event *eventpb.Event) bool) *EventList {
filtered := &EventList{}

iter := el.Iterator()
for event := iter.Next(); event != nil; event = iter.Next() {
if predicate(event) {
filtered.PushBack(event)
}
}

return filtered
}

// Iterator returns a pointer to an EventListIterator object used to iterate over the events in this list,
// starting from the beginning of the list.
func (el *EventList) Iterator() *EventListIterator {
Expand Down

0 comments on commit e100175

Please sign in to comment.