当前位置:网站首页>Collection library update version 1.4.0

Collection library update version 1.4.0

2022-01-15 02:32:40 yjf512

collection Library update 1.4.0 edition

collection The library has been in use , Weekend collection github Feedback on and contributor Modification of , Updated 1.4.0 edition .

This version does a few things :

Three types have been added , uint, uint32, uint64

These three types are also basic types , At present, basically all basic types have been covered , There are eleven types :

int32, int, int64, uint32, uint, uint64, float32, float64, string, object, objectPoint

increase Split and GroupBy Method

These two methods are actually a collection Grouping .Split According to the number , Divide the array into several parts , such as

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()

according to size by 3 Divide into 3 Parts of

IntCollection(3):{
	0:	1
	1:	2
	2:	3
}
IntCollection(3):{
	0:	4
	1:	5
	2:	6
}
IntCollection(2):{
	0:	7
	1:	8
}

and GroupBy It is a requirement raised by colleagues when using , Classify a function as needed , Then the output , Be similar to spark Medium GroupBy operator

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
}
*/

Actually, I did a few things :

1 Optimized some test cases , There are some direct dd Of , It feels ugly , Just take out

2 The document adds , Include readme And official documents

3 The official website has also been updated ,http://collection.funaio.cn/ . But it looks like github There is one action Mechanism , I haven't studied how to update github At the same time, update the... On your server vuepress.

The end , Have a nice weekend ~

版权声明
本文为[yjf512]所创,转载请带上原文链接,感谢
https://chowdera.com/2021/12/202112122246187471.html

随机推荐