-
Notifications
You must be signed in to change notification settings - Fork 0
/
column.go
60 lines (51 loc) · 1.02 KB
/
column.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package slice
import "reflect"
type Col []any
func Colunm(source any, key string) Col {
var rs []any
val := reflect.ValueOf(source)
if val.Kind() != reflect.Slice {
return rs
}
for i := 0; i < val.Len(); i++ {
k := val.Index(i).Elem()
f := k.FieldByName(key).Interface()
rs = append(rs, f)
}
return rs
}
func (e Col) Unique() Col {
tmp := map[any]any{}
for _, v := range e {
tmp[v] = v
}
var rs Col
for _, v := range tmp {
rs = append(rs, v)
}
return rs
}
// 此处没有判定类型是否相同,使用时自行判定
func (e Col) String() []string {
rs := []string{}
for _, v := range e {
rs = append(rs, v.(string))
}
return rs
}
// 此处没有判定类型是否相同,使用时自行判定
func (e Col) Uint32() []uint32 {
rs := []uint32{}
for _, v := range e {
rs = append(rs, v.(uint32))
}
return rs
}
// 此处没有判定类型是否相同,使用时自行判定
func (e Col) Uint64() []uint64 {
rs := []uint64{}
for _, v := range e {
rs = append(rs, v.(uint64))
}
return rs
}