github.com/isyscore/isc-gobase@v1.5.3-0.20231218061332-cbc7451899e9/isc/match.go (about) 1 package isc 2 3 func ListAll[T any](list []T, f func(T) bool) bool { 4 for _, e := range list { 5 if !f(e) { 6 return false 7 } 8 } 9 return true 10 } 11 12 func ListAny[T any](list []T, f func(T) bool) bool { 13 for _, e := range list { 14 if f(e) { 15 return true 16 } 17 } 18 return false 19 } 20 21 func ListNone[T any](list []T, f func(T) bool) bool { 22 for _, e := range list { 23 if f(e) { 24 return false 25 } 26 } 27 return true 28 } 29 30 func ListCount[T any](list []T, f func(T) bool) int { 31 num := 0 32 for _, e := range list { 33 if f(e) { 34 num++ 35 } 36 } 37 return num 38 } 39 40 func MapAll[K comparable, V any](m map[K]V, f func(K, V) bool) bool { 41 for k, v := range m { 42 if !f(k, v) { 43 return false 44 } 45 } 46 return true 47 } 48 49 func MapAny[K comparable, V any](m map[K]V, f func(K, V) bool) bool { 50 for k, v := range m { 51 if f(k, v) { 52 return true 53 } 54 } 55 return false 56 } 57 58 func MapNone[K comparable, V any](m map[K]V, f func(K, V) bool) bool { 59 for k, v := range m { 60 if f(k, v) { 61 return false 62 } 63 } 64 return true 65 } 66 67 func MapCount[K comparable, V any](m map[K]V, f func(K, V) bool) int { 68 num := 0 69 for k, v := range m { 70 if f(k, v) { 71 num++ 72 } 73 } 74 return num 75 } 76 77 func MapAllKey[K comparable, V any](m map[K]V, f func(K) bool) bool { 78 for k := range m { 79 if !f(k) { 80 return false 81 } 82 } 83 return true 84 } 85 86 func MapAnyKey[K comparable, V any](m map[K]V, f func(K) bool) bool { 87 for k := range m { 88 if f(k) { 89 return true 90 } 91 } 92 return false 93 } 94 95 func MapNoneKey[K comparable, V any](m map[K]V, f func(K) bool) bool { 96 for k := range m { 97 if f(k) { 98 return false 99 } 100 } 101 return true 102 } 103 104 func MapCountKey[K comparable, V any](m map[K]V, f func(K) bool) int { 105 num := 0 106 for k := range m { 107 if f(k) { 108 num++ 109 } 110 } 111 return num 112 } 113 114 func MapAllValue[K comparable, V any](m map[K]V, f func(V) bool) bool { 115 for _, v := range m { 116 if !f(v) { 117 return false 118 } 119 } 120 return true 121 } 122 123 func MapAnyValue[K comparable, V any](m map[K]V, f func(V) bool) bool { 124 for _, v := range m { 125 if f(v) { 126 return true 127 } 128 } 129 return false 130 } 131 132 func MapNoneValue[K comparable, V any](m map[K]V, f func(V) bool) bool { 133 for _, v := range m { 134 if f(v) { 135 return false 136 } 137 } 138 return true 139 } 140 141 func MapCountValue[K comparable, V any](m map[K]V, f func(V) bool) int { 142 num := 0 143 for _, v := range m { 144 if f(v) { 145 num++ 146 } 147 } 148 return num 149 }