-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstring_array.go
61 lines (49 loc) · 1.14 KB
/
string_array.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
61
package types
import (
"reflect"
"strings"
"github.com/ahmetb/go-linq/v3"
)
type StringArray []string
func NewStringArray(v ...string) StringArray {
return StringArray(v)
}
func (p StringArray) Contain(v string) bool {
return linq.From(p).Contains(v)
}
func (p StringArray) ContainAny(vs ...string) bool {
for _, v := range vs {
containFlag := p.Contain(v)
if containFlag {
return true
}
}
return false
}
func (p StringArray) Size() int {
return len(p)
}
func (p StringArray) Skip(skipVs ...string) StringArray {
var l []string
linq.From(p).WhereT(func(x string) bool {
skipFlag := linq.From(skipVs).Contains(x)
return !skipFlag
}).ToSlice(&l)
return l
}
func (p StringArray) Join(separate string) string {
return strings.Join(p, separate)
}
func (p StringArray) WherePage(page *Page) StringArray {
var out []string
linq.From(p).Skip(page.Offset()).
Take(page.GetLimit()).ToSlice(&out)
return out
}
func (p StringArray) TotalPageNo(page *Page) int {
lastPageNo := (p.Size() + page.GetLimit() - 1) / page.GetLimit()
return lastPageNo
}
func (p StringArray) DeepEqual(in StringArray) bool {
return reflect.DeepEqual(p, in)
}