https://github.com/martinohmann/collections-go
Golang collections for builtin types and generic slices
https://github.com/martinohmann/collections-go
generic-collections golang-collections immutable-collections mutable-collections
Last synced: 11 months ago
JSON representation
Golang collections for builtin types and generic slices
- Host: GitHub
- URL: https://github.com/martinohmann/collections-go
- Owner: martinohmann
- License: mit
- Created: 2019-10-04T17:47:27.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-11-03T10:23:45.000Z (over 6 years ago)
- Last Synced: 2025-06-09T02:03:43.152Z (about 1 year ago)
- Topics: generic-collections, golang-collections, immutable-collections, mutable-collections
- Language: Go
- Homepage:
- Size: 167 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
collections-go
==============
[](https://travis-ci.org/martinohmann/collections-go)
[](https://goreportcard.com/report/github.com/martinohmann/collections-go)
[](https://godoc.org/github.com/martinohmann/collections-go)
Mutable and immutable collections for commonly used builtin types. This package
includes collection types generated by
[collections-gen](https://github.com/martinohmann/collections-gen) for the
following builtins:
- `byte` ([`collections.Byte`](collections/byte.go), [`collections.ImmutableByte`](collections/immutable_byte.go))
- `[]byte` ([`collections.ByteSlice`](collections/byte_slice.go), [`collections.ImmutableByteSlice`](collections/immutable_byte_slice.go))
- `float32` ([`collections.Float32`](collections/float32.go), [`collections.ImmutableFloat32`](collections/immutable_float32.go))
- `float64` ([`collections.Float64`](collections/float64.go), [`collections.ImmutableFloat64`](collections/immutable_float64.go))
- `int` ([`collections.Int`](collections/int.go), [`collections.ImmutableInt`](collections/immutable_int.go))
- `int64` ([`collections.Int64`](collections/int64.go), [`collections.ImmutableInt64`](collections/immutable_int64.go))
- `int32` ([`collections.Int32`](collections/int32.go), [`collections.ImmutableInt32`](collections/immutable_int32.go))
- `string` ([`collections.String`](collections/string.go), [`collections.ImmutableString`](collections/immutable_string.go))
In addition to that the following hand crafted collection types are included:
- generic collections based on `interface{}` types and the `reflect` package
([`collections.Generic`](collections/generic.go),
[`collections.ImmutableGeneric`](collections/immutable.go))
Installation
------------
```sh
go get github.com/martinohmann/collections-go
```
Usage
-----
```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](https://godoc.org/github.com/martinohmann/collections-go/collections)
for all available collection methods.
License
-------
The source code of collections-go is released under the MIT License. See the
bundled LICENSE file for details.