From 6a42a23ef56a230ce6c8023898de575e02c1f640 Mon Sep 17 00:00:00 2001 From: xing Date: Sat, 24 Sep 2022 23:21:09 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9B=9E=E6=BB=9Afilter=EF=BC=8C=E4=B8=8D?= =?UTF-8?q?=E7=84=B6=E4=BC=9A=E6=94=B9=E5=8F=98=E5=8E=9F=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- helper/func.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/helper/func.go b/helper/func.go index ef6e0a5..2d36e0d 100644 --- a/helper/func.go +++ b/helper/func.go @@ -191,14 +191,13 @@ func SliceMap[T, R any](arr []T, fn func(T) R) []R { } func SliceFilter[T any](arr []T, fn func(T) bool) []T { - j := 0 + var r []T for _, t := range arr { if fn(t) { - arr[j] = t - j++ + r = append(r, t) } } - return arr[:j] + return r } func SliceReduce[T, R any](arr []T, fn func(T, R) R, r R) R {