Skip to content

Commit

Permalink
feat(pkg/oomstore): add methods IDs and Names for EntityList
Browse files Browse the repository at this point in the history
  • Loading branch information
jinghancc committed Feb 9, 2022
1 parent 51976b9 commit a7ce503
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions pkg/oomstore/types/entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,34 @@ func (l EntityList) Len() int {
return len(l)
}

func (l *EntityList) Find(find func(*Entity) bool) *Entity {
for _, e := range *l {
func (l EntityList) Find(find func(*Entity) bool) *Entity {
for _, e := range l {
if find(e) {
return e
}
}
return nil
}

func (l *EntityList) Filter(filter func(*Entity) bool) (rs EntityList) {
for _, e := range *l {
func (l EntityList) Filter(filter func(*Entity) bool) (rs EntityList) {
for _, e := range l {
if filter(e) {
rs = append(rs, e)
}
}
return
}

func (l EntityList) IDs() (ids []int) {
for _, entity := range l {
ids = append(ids, entity.ID)
}
return
}

func (l EntityList) Names() (names []string) {
for _, entity := range l {
names = append(names, entity.Name)
}
return
}

0 comments on commit a7ce503

Please sign in to comment.