Skip to content

Commit

Permalink
Action: added FilterF
Browse files Browse the repository at this point in the history
  • Loading branch information
rsteube committed Oct 9, 2023
1 parent a580cac commit c4c5b12
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions action.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,20 @@ func (a Action) Filter(values ...string) Action {
})
}

func (a Action) FilterF(f func(s ...string) bool) Action {
return ActionCallback(func(c Context) Action {
invoked := a.Invoke(c)
filtered := make(common.RawValues, 0)
for _, v := range invoked.rawValues {
if f(v.Value) {
filtered = append(filtered, v)
}
}
invoked.rawValues = filtered
return invoked.ToA()
})
}

// FilterArgs filters Context.Args
func (a Action) FilterArgs() Action {
return ActionCallback(func(c Context) Action {
Expand Down

0 comments on commit c4c5b12

Please sign in to comment.