DEFUNCT (I am not working on Go at the moment and this project will not receive any updates in the forseable future)
import "github.com/kelceydamage/collections"
Collections is a library of types and methods that make manipulating slices a lot easier by providing some basic functionality.
Included in collections are a couple interafaces:
this is a base interface and all slice-types in collections implement this interface.
type BaseSlice interface {
All() []interface{}
Overwrite(interface{})
Append(interface{})
Len() int
Swap(int, int)
TruncateLeft(int)
TruncateRight(int)
Mirror()
Index(interface{}) int
IndexRight(interface{}) int
}
type Slice interface {
BaseSlice
Sort()
Reverse()
}
type NumSlice interface {
Slice
Avg() float64
AvgNonZero() float64
StdDev() float64
Variance() float64
}
- IntSlice
- IntSliceM
- IntQueue
- IntStack
- Float64Slice
- Float64SliceM
- Float64Queue
- Float64Stack
- StringSlice
- BoolSlice
Collections is compatible with the built in Sort types, and should be familiar to use.
you can use a collections.IntSlice as a direct replacement for sort.IntSlice, while using all the features of Sort. This goes for all types included in Sort.
sort.Sort(sort.Reverse(sort.IntSlice(s)))
Is the same as:
sort.Sort(sort.Reverse(collections.IntSlice(s)))
However this is also the same as:
collections.IntSlice.Reverse()
And
collections.Reverse(IntSlice)