Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/ramalho/strset

A full-featured set type for string elements in Go
https://github.com/ramalho/strset

go golang golang-examples golang-package sets testify

Last synced: about 1 month ago
JSON representation

A full-featured set type for string elements in Go

Awesome Lists containing this project

README

        

# strset

[![GoDoc](https://godoc.org/github.com/standupdev/strset?status.svg)](https://godoc.org/github.com/standupdev/strset)

Full-featured Go `Set` type for `string` elements.

```golang
func Example() {
s1 := Make("red", "green", "blue", "yellow")
s2 := MakeFromText("yellow green white")
fmt.Println(s1.Intersection(s2))
// Output: Set{green yellow}
}
```

Some features of the `strset.Set` type:

* `Make` builds a set from zero or more strings (or `[]string...`).
* `MakeFromText` builds a set from a single string with elements separated by whitespace.
* `String` method returns elements in ascending order.
* Methods returning new sets: intersection, union, difference, symmetric difference.
* Methods updating receiver in-place for each operation above.
* `Pop` method to retrieve and delete one unspecified element.
* Need an immutable set? Just remove `updaters.go` from the build.
* 100% test coverage.
* Not thread-safe.

Happy hacking!