-
Notifications
You must be signed in to change notification settings - Fork 0
/
map.go
41 lines (37 loc) · 822 Bytes
/
map.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package gowed
// Extract unexpired data in slice
func ExtracMapUnexpiredData[K comparable, V Expirer](slice map[K]V) []V {
var result []V
for _, item := range slice {
if !item.IsExpired() {
result = append(result, item)
}
}
return result
}
// Extract expired data in slice
func ExtracMapExpiredData[K comparable, V Expirer](slice map[K]V) []V {
var result []V
for _, item := range slice {
if item.IsExpired() {
result = append(result, item)
}
}
return result
}
// Remove expired data in slice
func RemoveMapExpiredData[K comparable, V Expirer](m map[K]V) {
for k, v := range m {
if v.IsExpired() {
delete(m, k)
}
}
}
// Remove unexpired data in slice
func RemoveMapUnexpiredData[K comparable, V Expirer](m map[K]V) {
for k, v := range m {
if !v.IsExpired() {
delete(m, k)
}
}
}