-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnumber.go
43 lines (33 loc) · 939 Bytes
/
number.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
package collect
import (
"golang.org/x/exp/constraints"
)
type NumberCollection[T ~[]E, E constraints.Integer | constraints.Float] struct {
*SliceCollection[T, E]
}
func UseNumber[T ~[]E, E constraints.Integer | constraints.Float](items T) *NumberCollection[T, E] {
return &NumberCollection[T, E]{UseSlice[T, E](items)}
}
func (n *NumberCollection[T, E]) Sum() (total E) {
return Sum[T, E](n.All())
}
func (n *NumberCollection[T, E]) Min() E {
return Min[T, E](n.All())
}
func (n *NumberCollection[T, E]) Max() E {
return Max[T, E](n.All())
}
func (n *NumberCollection[T, E]) Sort() *NumberCollection[T, E] {
n.z = Sort[T, E](n.All())
return n
}
func (n *NumberCollection[T, E]) SortDesc() *NumberCollection[T, E] {
n.z = SortDesc[T, E](n.All())
return n
}
func (n *NumberCollection[T, E]) Avg() float64 {
return Avg[T, E](n.All())
}
func (n *NumberCollection[T, E]) Median() float64 {
return Median[T, E](n.All())
}