summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--aoc23/util.go6
1 files changed, 4 insertions, 2 deletions
diff --git a/aoc23/util.go b/aoc23/util.go
index 18ab3ec..414756a 100644
--- a/aoc23/util.go
+++ b/aoc23/util.go
@@ -138,10 +138,12 @@ func filter[V any](values []V, pred func(v V) bool) []V {
return filtered
}
-func anyMatch[V any](values []V, pred func(v V) bool) bool { return len(filter(values, pred)) > 0 }
+func frequency[V any](values []V, pred func(v V) bool) int { return len(filter(values, pred)) }
+
+func anyMatch[V any](values []V, pred func(v V) bool) bool { return frequency(values, pred) > 0 }
func allMatch[V any](values []V, pred func(v V) bool) bool {
- return len(filter(values, pred)) == len(values)
+ return frequency(values, pred) == len(values)
}
func noneMatch[V any](values []V, pred func(v V) bool) bool { return !anyMatch(values, pred) }