From 20bc7f2069b60647982df7da9afb0c67974a9e8a Mon Sep 17 00:00:00 2001 From: Jorropo Date: Sun, 17 Mar 2024 05:49:07 +0100 Subject: [PATCH] shortcut if there is only 1 argument to And or Or --- patterns.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/patterns.go b/patterns.go index f082802..9b0f1bf 100644 --- a/patterns.go +++ b/patterns.go @@ -79,6 +79,10 @@ const ( ) func And(ps ...Pattern) Pattern { + if len(ps) == 1 { + return ps[0] + } + return &pattern{ Op: and, Args: ps, @@ -86,6 +90,10 @@ func And(ps ...Pattern) Pattern { } func Or(ps ...Pattern) Pattern { + if len(ps) == 1 { + return ps[0] + } + return &pattern{ Op: or, Args: ps,