sugar

package module
v0.0.0-...-a90d991 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2023 License: MIT Imports: 9 Imported by: 0

README

lingotools

写go时所需工具

Documentation

Index

Constants

View Source
const (
	LeafNode = iota
	CompositeNode
)

Variables

This section is empty.

Functions

func Assign

func Assign[K comparable, V any](maps ...map[K]V) map[K]V

Assign merges multiple maps from left to right.

func Async

func Async[A any](f func() A) chan A

func AttemptWithDelay

func AttemptWithDelay(maxIteration int, delay time.Duration, f func(int, time.Duration) error) (int, time.Duration, error)

func CheckInSlice

func CheckInSlice[T constraints.Ordered](a T, s []T) bool

CheckInSlice check value in slice

func Clamp

func Clamp[T constraints.Ordered](value, min, max T) T

Clamp clamps number within the inclusive lower and upper bounds.

func Contains

func Contains[T comparable](collection []T, element T) bool

func DecorateFn

func DecorateFn(before, fn, after func()) func()

func DelOneInSlice

func DelOneInSlice[T constraints.Ordered](a T, old []T) (new []T)

DelOneInSlice delete one element of slice left->right

func Empty

func Empty[T any]() T

Empty returns an empty value.

func EntriesToMap

func EntriesToMap[K comparable, V any](entries []Entry[K, V]) map[K]V

func FanIn

func FanIn(in ...chan any) <-chan any

FanIn ...

func FanOut

func FanOut(ch <-chan any, n int) []chan any

func FiltrateBy

func FiltrateBy[K comparable, V any](in map[K]V, filtrate func(K, V) bool) map[K]V

func FiltrateByKeys

func FiltrateByKeys[K comparable, V any](in map[K]V, keys []K) map[K]V

func FiltrateByValues

func FiltrateByValues[K comparable, V comparable](in map[K]V, values []V) map[K]V

func Idiom

func Idiom(member any) func(obj any)

func IndexOf

func IndexOf[T comparable](collection []T, predicate func(T) bool) int

func Invert

func Invert[K comparable, V comparable](in map[K]V) map[V]K

func IsNil1

func IsNil1(i interface{}) bool

IsNil1 ...

func IsNil2

func IsNil2(i interface{}) bool

IsNil2 ...

func Keys

func Keys[K comparable, V any](in map[K]V) []K

func LastIndexOf

func LastIndexOf[T comparable](collection []T, predicate func(T) bool) int

func MapUpdateKeys

func MapUpdateKeys[K comparable, V any, R comparable](in map[K]V, iteratee func(K, V) R) map[R]V

MapUpdateKeys manipulates a map keys and transforms it to a map of another type.

func MapUpdateValues

func MapUpdateValues[K comparable, V any, R any](in map[K]V, iteratee func(K, V) R) map[K]R

MapUpdateValues manipulates a map values and transforms it to a map of another type.

func NewDebounce

func NewDebounce(duration time.Duration, fns ...func()) (func(), func())

func SliceFiltrate

func SliceFiltrate[V any](collection []V, filtrate func(V, int) bool) []V

func SliceGroupBy

func SliceGroupBy[T any, U comparable](collection []T, iteratee func(T) U) map[U][]T

func SliceUniq

func SliceUniq[T any, U comparable](collection []T, iteratee func(T) U) []T

func SliceUpdateElement

func SliceUpdateElement[T any, R any](collection []T, iteratee func(T, int) R) []R

func Synchronize

func Synchronize(opt ...sync.Locker) synchronize

func Ternary

func Ternary[T any](condition bool, ifOutput T, elseOutput T) T

func Try

func Try(callback func() error) (ok bool)

Try calls the function and return false in case of error.

func Values

func Values[K comparable, V any](in map[K]V) []V

func WaitSignal

func WaitSignal(fn func(sig os.Signal) bool)

Types

type AbstractFactory

type AbstractFactory interface {
	Create() Product
}

type Adapt

type Adapt interface {
	SpecifyDo()
}

type AdaptImpl

type AdaptImpl struct {
}

func (AdaptImpl) SpecifyDo

func (a AdaptImpl) SpecifyDo()

type Adapter

type Adapter struct {
	Adapt
}

func (*Adapter) Do

func (a *Adapter) Do()

type Builder

type Builder interface {
	Build(m any) Builder
	CompletedCheck() bool
}

type Cloneable

type Cloneable interface {
	Clone() Cloneable
}

type Component

type Component interface {
	Parent() Component
	SetParent(Component)
	Name() string
	SetName(string)
	AddChild(Component)
	Print(string)
}

func NewComponent

func NewComponent(kind int, name string) Component

type Composite

type Composite struct {
	// contains filtered or unexported fields
}

func NewComposite

func NewComposite() *Composite

func (*Composite) AddChild

func (c *Composite) AddChild(child Component)

func (*Composite) Name

func (c *Composite) Name() string

func (*Composite) Parent

func (c *Composite) Parent() Component

func (*Composite) Print

func (c *Composite) Print(pre string)

func (*Composite) SetName

func (c *Composite) SetName(name string)

func (*Composite) SetParent

func (c *Composite) SetParent(parent Component)

type Debounce

type Debounce struct {
	// contains filtered or unexported fields
}

type Entry

type Entry[K comparable, V any] struct {
	Key   K
	Value V
}

func MapToEntries

func MapToEntries[K comparable, V any](in map[K]V) []Entry[K, V]

type IfElse

type IfElse[T any] struct {
	Result T
	Ok     bool
}

func If

func If[T any](condition bool, result T) *IfElse[T]

func IfFn

func IfFn[T any](condition bool, resultFn func() T) *IfElse[T]

func (*IfElse[T]) Else

func (i *IfElse[T]) Else(result T) T

func (*IfElse[T]) ElseFn

func (i *IfElse[T]) ElseFn(resultFn func() T) T

func (*IfElse[T]) ElseIf

func (i *IfElse[T]) ElseIf(condition bool, result T) *IfElse[T]

func (*IfElse[T]) ElseIfFn

func (i *IfElse[T]) ElseIfFn(condition bool, resultFn func() T) *IfElse[T]

type Leaf

type Leaf struct {
	// contains filtered or unexported fields
}

func NewLeaf

func NewLeaf() *Leaf

func (*Leaf) AddChild

func (c *Leaf) AddChild(Component)

func (*Leaf) Name

func (c *Leaf) Name() string

func (*Leaf) Parent

func (c *Leaf) Parent() Component

func (*Leaf) Print

func (c *Leaf) Print(pre string)

func (*Leaf) SetName

func (c *Leaf) SetName(name string)

func (*Leaf) SetParent

func (c *Leaf) SetParent(parent Component)

type Mediator

type Mediator struct {
	// contains filtered or unexported fields
}

func GetMediator

func GetMediator() *Mediator

func (*Mediator) Changed

func (m *Mediator) Changed(i Member)

func (*Mediator) RegisterMember

func (m *Mediator) RegisterMember(from, to Member)

type Member

type Member interface {
	Process(a any)
	GetTransData() any
}

type Message

type Message struct {
}

type Product

type Product interface {
}

type PrototypeManager

type PrototypeManager struct {
	// contains filtered or unexported fields
}

func NewPrototypeManager

func NewPrototypeManager() *PrototypeManager

func (*PrototypeManager) Get

func (p *PrototypeManager) Get(name string) Cloneable

func (*PrototypeManager) Set

func (p *PrototypeManager) Set(name string, prototype Cloneable)

type Proxy

type Proxy struct {
	// contains filtered or unexported fields
}

func (*Proxy) Execute

func (p *Proxy) Execute()

type RingBuffer

type RingBuffer struct {
	// contains filtered or unexported fields
}

func NewRingBuffer

func NewRingBuffer(inputChannel <-chan any, outputChannel chan any) *RingBuffer

func (*RingBuffer) Run

func (r *RingBuffer) Run()

type Session

type Session struct {
	User      User
	Timestamp time.Time
}

type Subscription

type Subscription struct {
	Inbox chan Message
	// contains filtered or unexported fields
}

func (*Subscription) Publish

func (s *Subscription) Publish(msg Message) error

type SwitchCase

type SwitchCase[T comparable, R any] struct {
	Predicate T
	Result    R
	Ok        bool
}

func Switch

func Switch[T comparable, R any](predicate T) *SwitchCase[T, R]

func (*SwitchCase[T, R]) Case

func (s *SwitchCase[T, R]) Case(value T, result R) *SwitchCase[T, R]

func (*SwitchCase[T, R]) CaseFn

func (s *SwitchCase[T, R]) CaseFn(value T, resultFn func() R) *SwitchCase[T, R]

func (*SwitchCase[T, R]) Default

func (s *SwitchCase[T, R]) Default(result R) R

func (*SwitchCase[T, R]) DefaultFn

func (s *SwitchCase[T, R]) DefaultFn(resultFn func() R) R

type Target

type Target interface {
	Do()
}

func NewAdapter

func NewAdapter() Target

type Topic

type Topic struct {
	Subscribers    []Session
	MessageHistory []Message
	// contains filtered or unexported fields
}

func (*Topic) Delete

func (t *Topic) Delete() error

func (*Topic) Subscribe

func (t *Topic) Subscribe(uid uint64, name string) (Subscription, error)

func (*Topic) Unsubscribe

func (t *Topic) Unsubscribe(Subscription) error

type User

type User struct {
	ID   uint64
	Name string
}

Jump to

Keyboard shortcuts

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