gotypes

package module
v0.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 10, 2023 License: Apache-2.0 Imports: 3 Imported by: 1

README

gotypes

Provide generic wrappers for some basic types of golang, and extend some common types and type tools

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertTo

func ConvertTo[V any, R any](source Enumerable[V], convert func(V) R) []R
Example
data := map[string]int{}

data["a"] = 1
data["b"] = 2
data["c"] = 3

r := ConvertTo[int](GoMap[string, int](data), func(v int) string {
	return strconv.Itoa(v)
})
fmt.Println(r)
Output:
[1 2 3]

func ConvertToWithIndex

func ConvertToWithIndex[V any, R any](source Enumerable[V], convert func(int, V) R) []R

func ConvertToWithKey

func ConvertToWithKey[K comparable, V any, R any](source EnumerableWithKey[K, V], convert func(K, V) R) []R

Types

type Array added in v0.0.3

type Array[V any] interface {
	Container
	Enumerable2[int, V]

	Add(src ...V)
	Remove(index int)
	Get(index int) (V, bool)
	Set(index int, v V)
	Values() []V
	IndexOf(value V) int
}

type Container added in v0.0.3

type Container interface {
	Empty() bool
	Size() int
	RemoveAll()
}

type Enumerable

type Enumerable[V any] interface {
	Sizer
	EachValue(f func(value V))
}

type Enumerable2 added in v0.0.3

type Enumerable2[K any, V any] interface {
	// Each calls the given function once for each element, passing that element's index(or key) and value.
	Each(f func(index K, value V))
	// Range passes each element of the list to the given function and
	// break loop if the function returns false.
	Range(f func(index K, value V) bool)
	// Every passes each element of the list to the given function and
	// returns true if the function returns true for all elements.
	Every(f func(index K, value V) bool) bool
	// Some passes each element of the container to the given function and
	// returns true if the function ever returns true for any element.
	Some(f func(index K, value V) bool) bool
}

type EnumerableWithKey

type EnumerableWithKey[K comparable, V any] interface {
	Sizer
	Each(func(key K, value V))
}

type GoMap

type GoMap[K comparable, V any] map[K]V

func (GoMap[K, V]) Each

func (g GoMap[K, V]) Each(f func(key K, value V))

func (GoMap[K, V]) EachValue

func (g GoMap[K, V]) EachValue(f func(value V))

func (GoMap[K, V]) Size

func (g GoMap[K, V]) Size() int

type LinkedList added in v0.0.3

type LinkedList[T comparable] struct {
	// contains filtered or unexported fields
}

func NewLinkedList added in v0.0.3

func NewLinkedList[T comparable](values ...T) *LinkedList[T]

func (*LinkedList[T]) Add added in v0.0.3

func (list *LinkedList[T]) Add(values ...T)

func (*LinkedList[T]) Each added in v0.0.3

func (list *LinkedList[T]) Each(f func(index int, value T))

func (*LinkedList[T]) Empty added in v0.0.3

func (list *LinkedList[T]) Empty() bool

func (*LinkedList[T]) Every added in v0.0.3

func (list *LinkedList[T]) Every(f func(index int, value T) bool) bool

func (*LinkedList[T]) Get added in v0.0.3

func (list *LinkedList[T]) Get(index int) (T, bool)

func (*LinkedList[T]) IndexOf added in v0.0.3

func (list *LinkedList[T]) IndexOf(value T) int

func (*LinkedList[T]) Range added in v0.0.3

func (list *LinkedList[T]) Range(f func(index int, value T) bool)

func (*LinkedList[T]) Remove added in v0.0.3

func (list *LinkedList[T]) Remove(index int)

func (*LinkedList[T]) RemoveAll added in v0.0.3

func (list *LinkedList[T]) RemoveAll()

func (*LinkedList[T]) ReverseRange added in v0.0.3

func (list *LinkedList[T]) ReverseRange(f func(index int, value T) bool)

func (*LinkedList[T]) Set added in v0.0.3

func (list *LinkedList[T]) Set(index int, v T)

func (*LinkedList[T]) Size added in v0.0.3

func (list *LinkedList[T]) Size() int

func (*LinkedList[T]) Some added in v0.0.3

func (list *LinkedList[T]) Some(f func(index int, value T) bool) bool

func (*LinkedList[T]) Values added in v0.0.3

func (list *LinkedList[T]) Values() []T

type Map

type Map[K constraints.Basic, V any] interface {
	Get(key K) V
	Exist(key K) (ok bool)

	Store(key K, value V)
	Load(key K) (value V, ok bool)

	Range(f func(key K, value V) bool)
	Each(f func(key K, value V))

	Keys() []K
	Values() []V

	Size() int

	Delete(key K)
	DeleteAll()

	Data() map[K]V
}

type RWMutexMap

type RWMutexMap[K constraints.Basic, V any] struct {
	// contains filtered or unexported fields
}

RWMutexMap implements the SafeMap[K,V] interface

func NewRWMutexMap

func NewRWMutexMap[K constraints.Basic, V any]() *RWMutexMap[K, V]

func (*RWMutexMap[K, V]) Data

func (m *RWMutexMap[K, V]) Data() map[K]V

func (*RWMutexMap[K, V]) Delete

func (m *RWMutexMap[K, V]) Delete(key K)

func (*RWMutexMap[K, V]) DeleteAll

func (m *RWMutexMap[K, V]) DeleteAll()

func (*RWMutexMap[K, V]) Each

func (m *RWMutexMap[K, V]) Each(f func(key K, value V))

func (*RWMutexMap[K, V]) EachValue

func (m *RWMutexMap[K, V]) EachValue(f func(value V))

func (*RWMutexMap[K, V]) Exist

func (m *RWMutexMap[K, V]) Exist(key K) (ok bool)

func (*RWMutexMap[K, V]) Get

func (m *RWMutexMap[K, V]) Get(key K) V

func (*RWMutexMap[K, V]) Keys

func (m *RWMutexMap[K, V]) Keys() []K

func (*RWMutexMap[K, V]) Load

func (m *RWMutexMap[K, V]) Load(key K) (value V, ok bool)

func (*RWMutexMap[K, V]) LoadAndDelete

func (m *RWMutexMap[K, V]) LoadAndDelete(key K) (value V, loaded bool)

func (*RWMutexMap[K, V]) LoadOrStore

func (m *RWMutexMap[K, V]) LoadOrStore(key K, value V) (actual V, loaded bool)

func (*RWMutexMap[K, V]) Range

func (m *RWMutexMap[K, V]) Range(f func(key K, value V) bool)

func (*RWMutexMap[K, V]) Size

func (m *RWMutexMap[K, V]) Size() int

func (*RWMutexMap[K, V]) Store

func (m *RWMutexMap[K, V]) Store(key K, value V)

func (*RWMutexMap[K, V]) Values

func (m *RWMutexMap[K, V]) Values() []V

type RWSlice added in v0.0.3

type RWSlice[V any] struct {
	// contains filtered or unexported fields
}

func NewRWSlice added in v0.0.3

func NewRWSlice[V any]() *RWSlice[V]

func (RWSlice[V]) Add added in v0.0.3

func (rw RWSlice[V]) Add(src ...V)

func (RWSlice[V]) Capacity added in v0.0.3

func (rw RWSlice[V]) Capacity() int

func (RWSlice[V]) Data added in v0.0.3

func (rw RWSlice[V]) Data() []V

func (RWSlice[V]) Each added in v0.0.3

func (rw RWSlice[V]) Each(f func(index int, value V))

func (RWSlice[V]) Get added in v0.0.3

func (rw RWSlice[V]) Get(index int) V

func (RWSlice[V]) Length added in v0.0.3

func (rw RWSlice[V]) Length() int

func (RWSlice[V]) Range added in v0.0.3

func (rw RWSlice[V]) Range(f func(index int, value V) bool)

func (RWSlice[V]) Remove added in v0.0.3

func (rw RWSlice[V]) Remove(index int)

func (RWSlice[V]) Set added in v0.0.3

func (rw RWSlice[V]) Set(index int, v V)

type SafeArray added in v0.0.3

type SafeArray[V any] interface {
	Add(src ...V)
	Remove(index int)
	Set(index int, v V)
	Get(index int) V
	Length() int
	Capacity() int
	Range(f func(index int, value V) bool)
	Each(f func(index int, value V))
	Data() []V
}

type SafeMap

type SafeMap[K constraints.Basic, V any] interface {
	Map[K, V]

	LoadOrStore(key K, value V) (actual V, loaded bool)
	LoadAndDelete(key K) (value V, loaded bool)
}

type Sizer

type Sizer interface {
	Size() int
}

type SyncMap

type SyncMap[K constraints.Basic, V any] struct {
	// contains filtered or unexported fields
}

SyncMap efficiency is lower than the sync.Map, only suitable for small maps

func NewSyncMap

func NewSyncMap[K constraints.Basic, V any]() *SyncMap[K, V]

func (*SyncMap[K, V]) Data

func (s *SyncMap[K, V]) Data() map[K]V

func (*SyncMap[K, V]) Delete

func (s *SyncMap[K, V]) Delete(key K)

func (*SyncMap[K, V]) DeleteAll

func (s *SyncMap[K, V]) DeleteAll()

func (*SyncMap[K, V]) Each

func (s *SyncMap[K, V]) Each(f func(key K, value V))

func (*SyncMap[K, V]) EachValue

func (s *SyncMap[K, V]) EachValue(f func(value V))

func (*SyncMap[K, V]) Exist

func (s *SyncMap[K, V]) Exist(key K) (ok bool)

func (*SyncMap[K, V]) Get

func (s *SyncMap[K, V]) Get(key K) V

func (*SyncMap[K, V]) Keys

func (s *SyncMap[K, V]) Keys() []K

func (*SyncMap[K, V]) Load

func (s *SyncMap[K, V]) Load(key K) (value V, ok bool)

func (*SyncMap[K, V]) LoadAndDelete

func (s *SyncMap[K, V]) LoadAndDelete(key K) (value V, loaded bool)

func (*SyncMap[K, V]) LoadOrStore

func (s *SyncMap[K, V]) LoadOrStore(key K, value V) (actual V, loaded bool)

func (*SyncMap[K, V]) Range

func (s *SyncMap[K, V]) Range(f func(key K, value V) bool)

func (*SyncMap[K, V]) Size

func (s *SyncMap[K, V]) Size() int

Size Does not represent the actual size of the current map, just an estimate

func (*SyncMap[K, V]) Store

func (s *SyncMap[K, V]) Store(key K, value V)

func (*SyncMap[K, V]) Values

func (s *SyncMap[K, V]) Values() []V

Directories

Path Synopsis
Package geom implements a basic 2-D geometry library.
Package geom implements a basic 2-D geometry library.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL