https://github.com/chenhg5/collection
make golang map and slice powerful
https://github.com/chenhg5/collection
Last synced: about 2 months ago
JSON representation
make golang map and slice powerful
- Host: GitHub
- URL: https://github.com/chenhg5/collection
- Owner: chenhg5
- License: mit
- Created: 2019-07-30T07:18:54.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2020-09-25T14:46:23.000Z (over 4 years ago)
- Last Synced: 2025-04-10T00:18:25.489Z (about 2 months ago)
- Language: Go
- Homepage:
- Size: 201 KB
- Stars: 210
- Watchers: 10
- Forks: 37
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Go Collection
![]()
![]()
![]()
[](https://api.travis-ci.org/chenhg5/collection)Collection provides a fluent, convenient wrapper for working with arrays of data.
You can easily convert a map or an array into a Collection with the method ```Collect()```.
And then you can use the powerful and graceful apis of Collection to process the data.In general, Collection are immutable, meaning every Collection method returns an entirely new Collection instance
## doc
[here](https://godoc.org/github.com/chenhg5/collection#Collection)
## example
```golang
a := []int{2,3,4,5,6,7}Collect(a).Each(func(item, value interface{}) (interface{}, bool) {
return value.(decimal.Decimal).IntPart() + 2, false
}).ToIntArray()// []int{4,5,6,7,8,9}
b := []map[string]interface{}{
{"name": "Jack", "sex": 0},
{"name": "Mary", "sex": 1},
{"name": "Jane", "sex": 1},
}Collect(b).Where("name", "Jack").ToMapArray()[0]
// map[string]interface{}{"name": "Jack", "sex": 0}
```
[more examples](https://godoc.org/github.com/chenhg5/collection#pkg-examples)
## contribution
pr is very welcome.