ext

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2024 License: MIT Imports: 8 Imported by: 7

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckEmpty

func CheckEmpty[R any](value string, emptyFn func() R, notEmptyFn func(string) R) R

func CheckEmptyRun

func CheckEmptyRun(value string, emptyFn func(), notEmptyFn func(string))

func CheckZero

func CheckZero[T any, R any](value T, zeroFn func() R, notZeroFn func(T) R) R

func CheckZeroRun

func CheckZeroRun[T any](value T, zeroFn func(), notZeroFn func(T))

func DumpRequestBody

func DumpRequestBody(request *http.Request) (body []byte, err error)

func DumpResponseBody

func DumpResponseBody(response *http.Response) (body []byte, err error)

func EmptyThen

func EmptyThen(value string, emptyFn func() string) string

func EmptyThenRun

func EmptyThenRun(value string, emptyFn func())

func MapWithDefault

func MapWithDefault[K string | int, V any](v, def map[K]V) map[K]V

func MapWithItemKeyFunc added in v0.4.0

func MapWithItemKeyFunc[T any, K string | int](
	s []T, mapper fn.Function[T, K]) map[K]T

func MapWithItemKeyValueFunc added in v0.4.0

func MapWithItemKeyValueFunc[T any, K string | int, V any](
	s []T, keyMapper fn.Function[T, K], valueMapper fn.Function[T, V]) map[K]V

func MapWithKeyValueFunc added in v0.4.0

func MapWithKeyValueFunc[K string | int, V any, R any](
	v map[K]V, mapper fn.BiFunction[K, V, R]) map[K]R

func MapWithValueFunc added in v0.4.0

func MapWithValueFunc[K string | int, V any, R any](
	v map[K]V, mapper fn.Function[V, R]) map[K]R

func NotEmptyThen

func NotEmptyThen[R any](value string, notEmptyFn func(string) R) R

func NotEmptyThenRun

func NotEmptyThenRun(value string, notEmptyFn func(string))

func NotZeroThen

func NotZeroThen[T any, R any](value T, notZeroFn func(T) R) R

func NotZeroThenRun

func NotZeroThenRun[T any](value T, notZeroFn func(T))

func Publish

func Publish(topic string, msg any)

func SliceWithItemFunc added in v0.4.0

func SliceWithItemFunc[T any, R any](
	s []T, mapper fn.Function[T, R]) []R

func Subscribe

func Subscribe(topic string, subscriber Subscriber)

func Unsubscribe

func Unsubscribe(topic string, subscriber Subscriber)

func ZeroThen

func ZeroThen[T any](value T, zeroFn func() T) T

func ZeroThenRun

func ZeroThenRun[T any](value T, zeroFn func())

Types

type Consumers

type Consumers[T any] interface {
	Accept(T)
	CheckedAccept(T) error
	AppendConsumer(fn.Consumer[T]) Consumers[T]
	RemoveConsumer(fn.Consumer[T]) Consumers[T]
}

func NewConsumers added in v0.2.0

func NewConsumers[T any]() Consumers[T]

type Ordered

type Ordered interface {
	Order() string
}

type OrderedSlice

type OrderedSlice[T Ordered] []T

func JoinOrdered

func JoinOrdered[T Ordered](items ...T) OrderedSlice[T]

func (OrderedSlice[T]) Len

func (x OrderedSlice[T]) Len() int

func (OrderedSlice[T]) Less

func (x OrderedSlice[T]) Less(i, j int) bool

func (OrderedSlice[T]) Sort

func (x OrderedSlice[T]) Sort()

func (OrderedSlice[T]) Swap

func (x OrderedSlice[T]) Swap(i, j int)

type PubSub

type PubSub interface {
	Subscribe(string, Subscriber)
	Unsubscribe(string, Subscriber)
	Publish(string, any)
}

func NewPubSub

func NewPubSub() PubSub

type Registry

type Registry[T any] interface {
	Register(string, T) error
	Get(string) (T, error)
}

func NewDefaultRegistry

func NewDefaultRegistry[T any](defName string, defItem T) Registry[T]

func NewSimpleRegistry

func NewSimpleRegistry[T any]() Registry[T]

type RegistryError

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

func (*RegistryError) Error

func (e *RegistryError) Error() string

type SubscribeConsumer

type SubscribeConsumer[T any] struct {
	fn.Consumer[T]
}

func (SubscribeConsumer[T]) Subscribe

func (s SubscribeConsumer[T]) Subscribe(msg any)

type Subscriber

type Subscriber interface {
	Subscribe(any)
}

func JoinSubscribers

func JoinSubscribers(subscribers ...Subscriber) Subscriber

func SubChan

func SubChan[T any](ch chan T) Subscriber

func SubConsumer

func SubConsumer[T any](c fn.Consumer[T]) Subscriber

func SubFn

func SubFn[T any](f func(T)) Subscriber

type Subscribers

type Subscribers []Subscriber

func (Subscribers) Subscribe

func (s Subscribers) Subscribe(msg any)

Jump to

Keyboard shortcuts

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