Need help with collection?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

chenhg5
146 Stars 23 Forks MIT License 31 Commits 5 Opened issues

Description

make golang map and slice powerful

Services available

!
?

Need anything else?

Contributors list

# 4,023
Go
dataviz
Gin
golang
31 commits

Go Collection

golang GoDoc license Build Status

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

example

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

contribution

pr is very welcome.

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.