From c4c5b129c347c26ac659708b3c0346ff96436972 Mon Sep 17 00:00:00 2001 From: rsteube Date: Mon, 9 Oct 2023 23:00:08 +0200 Subject: [PATCH] Action: added FilterF --- action.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/action.go b/action.go index b833e15a2..8ed5c5f18 100644 --- a/action.go +++ b/action.go @@ -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 {