-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9585123
commit 6b0d8b6
Showing
2 changed files
with
100 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
# collection库更新1.4.0版本 | ||
|
||
|
||
|
||
collection库一直在生产环境中有使用到,集合github上的反馈以及contributor的修改,周末整理了一下,发布了1.4.0版本。 | ||
|
||
|
||
|
||
这个版本做了几个事情: | ||
|
||
1 增加了三种类型, uint, uint32, uint64。 | ||
|
||
这三种类型也算基础类型了,目前基本上已经把所有基础类型都覆盖了,一共十一种类型: | ||
|
||
int32, int, int64, uint32, uint, uint64, float32, float64, string, object, objectPoint | ||
|
||
2 增加Split和GroupBy方法 | ||
|
||
这两个方法其实都是将一个collection进行分组。Split是根据个数,将数组分成几份,比如 | ||
|
||
```go | ||
intColl := NewIntCollection([]int{1, 2, 3, 4, 5, 6, 7, 8}) | ||
ret := intColl.Split(3) | ||
|
||
if len(ret) != 3 { | ||
t.Fatal("split len not right") | ||
} | ||
|
||
ret[0].DD() | ||
ret[1].DD() | ||
ret[2].DD() | ||
``` | ||
|
||
|
||
|
||
按照size为3分成3个部分 | ||
|
||
|
||
|
||
``` | ||
IntCollection(3):{ | ||
0: 1 | ||
1: 2 | ||
2: 3 | ||
} | ||
IntCollection(3):{ | ||
0: 4 | ||
1: 5 | ||
2: 6 | ||
} | ||
IntCollection(2):{ | ||
0: 7 | ||
1: 8 | ||
} | ||
``` | ||
|
||
|
||
|
||
而GroupBy 是同事使用的时候提的一个需求,需要按照某个函数进行归类,然后输出,类似于spark中的GroupBy算子 | ||
|
||
|
||
|
||
``` | ||
func TestInt32Collection_GroupBy(t *testing.T) { | ||
objColl := NewInt32Collection([]int32{1, 1, 20, 4}) | ||
groupBy := objColl.GroupBy(func(item interface{}, i2 int) interface{} { | ||
foo := item.(int32) | ||
return foo | ||
}) | ||
for k, collection := range groupBy { | ||
t.Log(k) | ||
collection.DD() | ||
} | ||
} | ||
/* | ||
=== RUN TestInt32Collection_GroupBy | ||
/Users/yejianfeng/Documents/workspace/collection/int32_collection_test.go:97: 1 | ||
Int32Collection(2):{ | ||
0: 1 | ||
1: 1 | ||
} | ||
/Users/yejianfeng/Documents/workspace/collection/int32_collection_test.go:97: 20 | ||
Int32Collection(1):{ | ||
0: 20 | ||
} | ||
/Users/yejianfeng/Documents/workspace/collection/int32_collection_test.go:97: 4 | ||
Int32Collection(1):{ | ||
0: 4 | ||
} | ||
*/ | ||
``` | ||
|
||
|
||
|