Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hanson/collection
https://github.com/hanson/collection
Last synced: 24 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/hanson/collection
- Owner: Hanson
- License: mit
- Created: 2023-03-20T13:24:06.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-08-28T08:54:42.000Z (2 months ago)
- Last Synced: 2024-08-28T10:12:39.617Z (2 months ago)
- Language: Go
- Size: 16.6 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# collection
Coming soon ...
## Support function
* [KeyBy](#KeyBy)
* [KeyBySlice](#KeyBySlice)
* [PluckUint64](#PluckUint64)
* [PluckString](#PluckString)## Usage
### KeyBy
```
type Person struct {
Name string
Age int
}
people := []*Person{
{Name: "Alice", Age: 25},
{Name: "Bob", Age: 30},
{Name: "Charlie", Age: 35},
}
result := KeyBy(people, "Name").(map[string]*Person)result["Alice"].Age // 25
```### KeyBySlice
```
type Person struct {
Name string
Id int
}
people := []*Person{
{
Name: "Alice",
Id: 1,
},
{
Name: "Bill",
Id: 1,
},
{
Name: "Bill",
Id: 3,
},
}result := KeyBySlice(people, "Id").(map[int][]*Person)
result[1] // [0xc000008120 0xc000008138]
result[1][0] // &{Alice 1}
```### PluckUint64
```
type testStruct struct {
ID uint64
Name string
}tests := []*testStruct{
{ID: 1, Name: "Alice"},
{ID: 2, Name: "Bob"},
{ID: 3, Name: "Charlie"},
}result := PluckUint64(tests, "ID")
// result: []uint64{1, 2, 3}
```## Respect
https://laravel.com/docs/10.x/collections
https://github.com/elliotchance/pie (Most of the code is copied from here.)## License
MIT