An open API service indexing awesome lists of open source software.

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

Awesome Lists containing this project

README

          

collections-go
==============

[![Build Status](https://travis-ci.org/martinohmann/collections-go.svg?branch=master)](https://travis-ci.org/martinohmann/collections-go)
[![Go Report Card](https://goreportcard.com/badge/github.com/martinohmann/collections-go?style=flat)](https://goreportcard.com/report/github.com/martinohmann/collections-go)
[![GoDoc](https://godoc.org/github.com/martinohmann/collections-go?status.svg)](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.