# Functions
GroupingBy 分组的Collect 方法,结合stream使用
eg:
res1 := stream.Collect(stream.Of(
TestItem{itemNum: 1, itemValue: "item1"},
TestItem{itemNum: 2, itemValue: "item2"},
TestItem{itemNum: 3, itemValue: "item2"},
TestItem{itemNum: 5, itemValue: "item2"},
TestItem{itemNum: 2, itemValue: "item2"},
TestItem{itemNum: 4, itemValue: "item4"},
TestItem{itemNum: 0, itemValue: "item4"},
TestItem{itemNum: 4, itemValue: "item5"},
TestItem{itemNum: 9, itemValue: "item5"},
).Filter(func(item TestItem) bool {
if item.itemNum != 1 {
return true
}
return false
}), collectors.GroupingBy(func(t TestItem) string {
return t.itemValue
}, func(t TestItem) int {
return t.itemNum
}, func(t1 []int) {
sort.Slice(t1, func(i, j int) bool {
return t1[i] < t1[j]
})
}))
fmt.Println(res1)
*/.
Statistic Collect 统计方法
可以和stream结合使用,如下的代码来使用:
eg:
type TestItem struct {
itemNum int
itemValue string
}
res := stream.Collect(stream.Of(
TestItem{itemNum: 1, itemValue: "item1"},
TestItem{itemNum: 2, itemValue: "3tem21"},
TestItem{itemNum: 2, itemValue: "2tem22"},
TestItem{itemNum: 2, itemValue: "1tem22"},
TestItem{itemNum: 2, itemValue: "4tem23"},
TestItem{itemNum: 3, itemValue: "item3"},
).MapToInt(func(t TestItem) int {
return t.itemNum * 2
}), collectors.Statistic[int]())
println(res.GetSum())
println(res.GetAverage())
*/.
ToMap 切片转Map的Collect方法, 结合stream使用:
eg:
type TestItemS struct {
itemNum int `json:"itemNum"`
itemValue string `json:"itemValue"`
}
res1 := stream.Collect(stream.Of(
TestItemS{itemNum: 1, itemValue: "item1"},
TestItemS{itemNum: 2, itemValue: "item2"},
TestItemS{itemNum: 3, itemValue: "item3"},
TestItemS{itemNum: 4, itemValue: "item4"},
TestItemS{itemNum: 5, itemValue: "item4"},
TestItemS{itemNum: 4, itemValue: "item5"},
), collectors.ToMap(func(t TestItemS) string {
return t.itemValue
}, func(item TestItemS) int {
return item.itemNum
}, func(v1, v2 int) int {
return v2
}))
println(res1)
*/.
# Structs
No description provided by the author
SumStatistics 这个struct 是一些简单统计的聚合类
*/.
# Interfaces
Collector See java: stream <T> – the type of input elements to the reduction operation <A> – the mutable accumulation type of the reduction operation (often hidden as an implementation detail) <R> – the result type of the reduction operation.
No description provided by the author
Number 抽象出常用的运算类型
*/.
# Type aliases
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author