A type-safe and thread-safe array type in Go
. If you are tired of slices
and the Go list.list
is not powerful enough for you, than you are at the right place.
Custom types should be always registred first.
Registry functions:
GetTypeName(value interface{}) string
IsTypeRegistered(typeName string) bool
RegisterType(value interface{})
RegisteredTypes() []string
Types:
type Element interface{}
type Array struct {
// contains filtered or unexported fields
}
Array constructor:
ArrayOfType(typeName string) *Array
Array methods:
SetType(typeName string) *Array
Type() string
Append(newElement Element)
InsertAtIndex(newElement Element, index int)
RemoveAtIndex(index int) Element
Remove(element Element)
RemoveFirst() Element
RemoveLast() Element
RemoveAll()
Count() int
IsEmpty() bool
ContainsElement(element Element) bool
IndexForElement(element Element) int
ElementAtIndex(index int) Element
FirstElement() Element
LastElement() Element
SetAtIndex(element Element, index int)
String() string
TODO-List:
- more examples
- deeper explanation
- delegation callbacks (to make the array observable)
- code enhancement
BSD license. See the LICENSE
file for details.