Mutable and immutable collections for commonly used builtin types. This package includes collection types generated by collections-gen for the following builtins:
byte
(collections.Byte
,collections.ImmutableByte
)[]byte
(collections.ByteSlice
,collections.ImmutableByteSlice
)float32
(collections.Float32
,collections.ImmutableFloat32
)float64
(collections.Float64
,collections.ImmutableFloat64
)int
(collections.Int
,collections.ImmutableInt
)int64
(collections.Int64
,collections.ImmutableInt64
)int32
(collections.Int32
,collections.ImmutableInt32
)string
(collections.String
,collections.ImmutableString
)
In addition to that the following hand crafted collection types are included:
- generic collections based on
interface{}
types and thereflect
package (collections.Generic
,collections.ImmutableGeneric
)
go get github.com/martinohmann/collections-go
c := collections.NewString([]string{"foo", "bar", "baz"})
items := c.
Filter(func(item string) bool {
return strings.HasPrefix(item, "ba")
}).
Reverse().
Prepend("qux").
Items()
fmt.Println(items)
// Output:
// [qux baz bar]
Check out the godocs for all available collection methods.
The source code of collections-go is released under the MIT License. See the bundled LICENSE file for details.