Documentation
¶
Index ¶
- func Camel(s string) string
- func Cased(s string, fn ...CasedFn) string
- func Clamp[T Float](v T, minimum T, maximum T) T
- func Clamp01[T Float](v T) T
- func ClampFit[T Float](x T, oldMin T, oldMax T, newMin T, newMax T) T
- func ClampFit01[T Float](x T, newMin T, newMax T) T
- func CtxSlog(ctx context.Context) (logger *slog.Logger, ok bool)
- func CtxWithSlog(ctx context.Context, slog *slog.Logger) context.Context
- func DebounceWithMaxWait(waitTime time.Duration, maxWaitTime time.Duration, ...) func(context.Context) error
- func EaseInBack[T Float](t T) T
- func EaseInBounce[T Float](t T) T
- func EaseInCirc[T Float](t T) T
- func EaseInCubic[T Float](t T) T
- func EaseInElastic[T Float](t T) T
- func EaseInExpo[T Float](t T) T
- func EaseInOutBack[T Float](t T) T
- func EaseInOutBounce[T Float](t T) T
- func EaseInOutCirc[T Float](t T) T
- func EaseInOutCubic[T Float](t T) T
- func EaseInOutElastic[T Float](t T) T
- func EaseInOutExpo[T Float](t T) T
- func EaseInOutQuad[T Float](t T) T
- func EaseInOutQuart[T Float](t T) T
- func EaseInOutQuint[T Float](t T) T
- func EaseInOutSine[T Float](t T) T
- func EaseInQuad[T Float](t T) T
- func EaseInQuart[T Float](t T) T
- func EaseInQuint[T Float](t T) T
- func EaseInSine[T Float](t T) T
- func EaseLinear[T Float](t T) T
- func EaseOutBack[T Float](t T) T
- func EaseOutBounce[T Float](t T) T
- func EaseOutCirc[T Float](t T) T
- func EaseOutCubic[T Float](t T) T
- func EaseOutElastic[T Float](t T) T
- func EaseOutExpo[T Float](t T) T
- func EaseOutQuad[T Float](t T) T
- func EaseOutQuart[T Float](t T) T
- func EaseOutQuint[T Float](t T) T
- func EaseOutSine[T Float](t T) T
- func Fit[T Float](x T, oldMin T, oldMax T, newMin T, newMax T) T
- func Fit01[T Float](x T, newMin T, newMax T) T
- func FitMax[T Float](x T, newMax T) T
- func FreePort() (port int, err error)
- func Kebab(s string) string
- func Lower(s string) string
- func MusicalRatio(name MusicalRatioName) float64
- func Pascal(s string) string
- func RandIntRange[T Integer](r *rand.Rand, min, max T) T
- func RandNegOneToOneClamped[T Float](r *rand.Rand) T
- func RandSliceItem[T any](r *rand.Rand, slice []T) T
- func ReadFloat32(r io.Reader) (float32, error)
- func ReadInt32(r io.Reader) (int32, error)
- func ReadInt64(r io.Reader) (int64, error)
- func ReadString(r io.Reader) (string, error)
- func ReadUint8(r io.Reader) (uint8, error)
- func ReadUint32(r io.Reader) (uint32, error)
- func ReadUint64(r io.Reader) (uint64, error)
- func RoundFit01[T Float](x T, newMin T, newMax T) T
- func ScreamingSnake(s string) string
- func Snake(s string) string
- func Upper(s string) string
- func WriteFloat32(w io.Writer, v float32) error
- func WriteInt32(w io.Writer, v int32) error
- func WriteInt64(w io.Writer, v int64) error
- func WriteString(w io.Writer, s string) error
- func WriteUint8(w io.Writer, v uint8) error
- func WriteUint32(w io.Writer, v uint32) error
- func WriteUint64(w io.Writer, v uint64) error
- type CasedFn
- type CasedString
- type CtxErrFunc
- type CtxKey
- type EasingFunc
- type EasingMode
- type EventBus
- type EventBusAsync
- type EventBusSync
- type Float
- type Handle
- type Integer
- type MusicalRatioName
- type Pool
- type PoolOption
- type SparseSet
- func (s *SparseSet[T]) Cap() int
- func (s *SparseSet[T]) Clear()
- func (s *SparseSet[T]) Contains(h Handle) bool
- func (s *SparseSet[T]) Get(h Handle) (T, bool)
- func (s *SparseSet[T]) GetRef(h Handle) (*T, bool)
- func (s *SparseSet[T]) Handles() []Handle
- func (s *SparseSet[T]) Insert(v T) Handle
- func (s *SparseSet[T]) Len() int
- func (s *SparseSet[T]) Range(f func(h Handle, v *T) bool)
- func (s *SparseSet[T]) Remove(h Handle) bool
- func (s *SparseSet[T]) Reserve(n int)
- func (s *SparseSet[T]) ReserveSlots(n int)
- func (s *SparseSet[T]) Values() []T
- type Subscriber
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ClampFit01 ¶
func ClampFit01[T Float](x T, newMin T, newMax T) T
func CtxWithSlog ¶ added in v0.0.3
func DebounceWithMaxWait ¶ added in v0.5.3
func DebounceWithMaxWait(waitTime time.Duration, maxWaitTime time.Duration, fn func(context.Context) error) func(context.Context) error
DebounceWithMaxWait creates a debounced function that waits for a quiet period before executing, but guarantees execution within a maximum wait time.
func EaseInOutBack ¶ added in v0.5.4
func EaseInOutBack[T Float](t T) T
func EaseInOutBounce ¶ added in v0.5.4
func EaseInOutBounce[T Float](t T) T
func EaseInOutCirc ¶ added in v0.5.4
func EaseInOutCirc[T Float](t T) T
func EaseInOutCubic ¶ added in v0.5.4
func EaseInOutCubic[T Float](t T) T
func EaseInOutElastic ¶ added in v0.5.4
func EaseInOutElastic[T Float](t T) T
func EaseInOutExpo ¶ added in v0.5.4
func EaseInOutExpo[T Float](t T) T
func EaseInOutQuad ¶ added in v0.5.4
func EaseInOutQuad[T Float](t T) T
func EaseInOutQuart ¶ added in v0.5.4
func EaseInOutQuart[T Float](t T) T
func EaseInOutQuint ¶ added in v0.5.4
func EaseInOutQuint[T Float](t T) T
func EaseInOutSine ¶ added in v0.5.4
func EaseInOutSine[T Float](t T) T
func EaseOutBack ¶ added in v0.5.4
func EaseOutBack[T Float](t T) T
func EaseOutBounce ¶ added in v0.5.4
func EaseOutBounce[T Float](t T) T
func EaseOutCirc ¶ added in v0.5.4
func EaseOutCirc[T Float](t T) T
func EaseOutCubic ¶ added in v0.5.4
func EaseOutCubic[T Float](t T) T
func EaseOutElastic ¶ added in v0.5.4
func EaseOutElastic[T Float](t T) T
func EaseOutExpo ¶ added in v0.5.4
func EaseOutExpo[T Float](t T) T
func EaseOutQuad ¶ added in v0.5.4
func EaseOutQuad[T Float](t T) T
func EaseOutQuart ¶ added in v0.5.4
func EaseOutQuart[T Float](t T) T
func EaseOutQuint ¶ added in v0.5.4
func EaseOutQuint[T Float](t T) T
func EaseOutSine ¶ added in v0.5.4
func EaseOutSine[T Float](t T) T
func MusicalRatio ¶ added in v0.5.5
func MusicalRatio(name MusicalRatioName) float64
func RandIntRange ¶
func RandNegOneToOneClamped ¶
func RandSliceItem ¶ added in v0.3.1
func ReadFloat32 ¶ added in v0.8.4
ReadFloat32 reads a little-endian IEEE 754 float32.
func ReadString ¶ added in v0.8.4
ReadString reads a length-prefixed string with a uint32 length.
func ReadUint32 ¶ added in v0.8.4
ReadUint32 reads a little-endian uint32.
func ReadUint64 ¶ added in v0.8.4
ReadUint64 reads a little-endian uint64.
func RoundFit01 ¶
func RoundFit01[T Float](x T, newMin T, newMax T) T
func ScreamingSnake ¶ added in v0.3.8
func WriteFloat32 ¶ added in v0.8.4
WriteFloat32 writes v in little-endian IEEE 754 binary form.
func WriteInt32 ¶ added in v0.8.4
WriteInt32 writes v in little-endian order.
func WriteInt64 ¶ added in v0.8.4
WriteInt64 writes v in little-endian order.
func WriteString ¶ added in v0.8.4
WriteString writes a length-prefixed string with a uint32 length.
func WriteUint8 ¶ added in v0.8.4
WriteUint8 writes v in little-endian order.
func WriteUint32 ¶ added in v0.8.4
WriteUint32 writes v in little-endian order.
Types ¶
type CasedString ¶
type CasedString struct {
Original string
Pascal string
Camel string
Snake string
ScreamingSnake string
Kebab string
Upper string
Lower string
}
func ToCasedString ¶ added in v0.0.26
func ToCasedString(s string) CasedString
type CtxErrFunc ¶
func CallNTimesWithDelay ¶ added in v0.3.14
func CallNTimesWithDelay(d time.Duration, n int, fn CtxErrFunc) CtxErrFunc
func Debounce ¶ added in v0.3.14
func Debounce(d time.Duration, fn CtxErrFunc) CtxErrFunc
Debounce will only call the function after d duration has passed since the last call.
func Throttle ¶ added in v0.3.14
func Throttle(d time.Duration, fn CtxErrFunc) CtxErrFunc
Throttle will only allow the function to be called once every d duration.
type EasingFunc ¶ added in v0.5.4
type EasingFunc[T Float] func(t T) T
EasingFunc is a function that takes a normalized time t in [0,1] and returns the eased value in [0,1].
func Ease ¶ added in v0.5.4
func Ease[T Float](mode EasingMode) EasingFunc[T]
Ease returns a named easing function. Unknown names fall back to linear. Accepted names are case-insensitive and allow dashes/underscores/spaces, e.g.:
"linear", "in-quad", "easeInCubic", "inout-sine", "out_bounce", etc.
type EasingMode ¶ added in v0.5.5
type EasingMode string
const ( EasingModeLinear EasingMode = "linear" EasingModeInQuad EasingMode = "inquad" EasingModeOutQuad EasingMode = "outquad" EasingModeInOutQuad EasingMode = "inoutquad" EasingModeInCubic EasingMode = "incubic" EasingModeOutCubic EasingMode = "outcubic" EasingModeInOutCubic EasingMode = "inoutcubic" EasingModeInQuart EasingMode = "inquart" EasingModeOutQuart EasingMode = "outquart" EasingModeInOutQuart EasingMode = "inoutquart" EasingModeInQuint EasingMode = "inquint" EasingModeOutQuint EasingMode = "outquint" EasingModeInOutQuint EasingMode = "inoutquint" EasingModeInSine EasingMode = "insine" EasingModeOutSine EasingMode = "outsine" EasingModeInOutSine EasingMode = "inoutsine" EasingModeInExpo EasingMode = "inexpo" EasingModeOutExpo EasingMode = "outexpo" EasingModeInOutExpo EasingMode = "inoutexpo" EasingModeInCirc EasingMode = "incirc" EasingModeOutCirc EasingMode = "outcirc" EasingModeInOutCirc EasingMode = "inoutcirc" EasingModeInElastic EasingMode = "inelastic" EasingModeOutElastic EasingMode = "outelastic" EasingModeInOutElastic EasingMode = "inoutelastic" EasingModeInBack EasingMode = "inback" EasingModeOutBack EasingMode = "outback" EasingModeInOutBack EasingMode = "inoutback" EasingModeInBounce EasingMode = "inbounce" EasingModeOutBounce EasingMode = "outbounce" EasingModeInOutBounce EasingMode = "inoutbounce" )
type EventBus ¶ added in v0.4.4
type EventBus[T any] interface { Subscribe(ctx context.Context, fn Subscriber[T]) context.CancelFunc Emit(ctx context.Context, msg T) error Count() int }
type EventBusAsync ¶ added in v0.4.4
type EventBusAsync[T any] struct { // contains filtered or unexported fields }
func NewEventBusAsync ¶ added in v0.4.4
func NewEventBusAsync[T any]() *EventBusAsync[T]
func (*EventBusAsync[T]) Emit ¶ added in v0.4.4
func (b *EventBusAsync[T]) Emit(ctx context.Context, msg T) error
func (EventBusAsync) Subscribe ¶ added in v0.4.4
func (b EventBusAsync) Subscribe(ctx context.Context, fn Subscriber[T]) context.CancelFunc
type EventBusSync ¶ added in v0.4.4
type EventBusSync[T any] struct { // contains filtered or unexported fields }
func NewEventBusSync ¶ added in v0.4.4
func NewEventBusSync[T any]() *EventBusSync[T]
func (*EventBusSync[T]) Emit ¶ added in v0.4.4
func (b *EventBusSync[T]) Emit(ctx context.Context, msg T) error
func (EventBusSync) Subscribe ¶ added in v0.4.4
func (b EventBusSync) Subscribe(ctx context.Context, fn Subscriber[T]) context.CancelFunc
type Handle ¶ added in v0.6.0
Handle is a stable reference to an element in a SparseSet. Index and Generation are both uint32. A handle is valid if its generation matches the current generation for its slot in the set in which it was created.
type MusicalRatioName ¶ added in v0.5.5
type MusicalRatioName string
const ( MusicalRatioMinorSecond MusicalRatioName = "Minor Second" MusicalRatioMajorSecond MusicalRatioName = "Major Second" MusicalRatioMinorThird MusicalRatioName = "Minor Third" MusicalRatioMajorThird MusicalRatioName = "Major Third" MusicalRatioPerfectFourth MusicalRatioName = "Perfect Fourth" MusicalRatioAugmentedFourth MusicalRatioName = "Augmented Fourth" MusicalRatioPerfectFifth MusicalRatioName = "Perfect Fifth" MusicalRatioGoldenRatio MusicalRatioName = "Golden Ratio" MusicalRatioMinorSixth MusicalRatioName = "Minor Sixth" MusicalRatioMajorSixth MusicalRatioName = "Major Sixth" MusicalRatioMajorSeventh MusicalRatioName = "Major Seventh" MusicalRatioOctave MusicalRatioName = "Octave" )
type Pool ¶ added in v0.2.1
type Pool[T any] struct { // contains filtered or unexported fields }
A Pool is a generic wrapper around a sync.Pool.
func New ¶ added in v0.2.1
func New[T any](fn func() T, opts ...PoolOption[T]) *Pool[T]
New creates a new Pool with the provided new function.
The equivalent sync.Pool construct is "sync.Pool{New: fn}"
func (*Pool[T]) Clear ¶ added in v0.8.3
Clear resets the pool. If keepCapacity is true, the pool is left intact.
func (*Pool[T]) Get ¶ added in v0.2.1
func (p *Pool[T]) Get() T
Get is a generic wrapper around sync.Pool's Get method.
func (*Pool[T]) GetWithReset ¶ added in v0.8.3
func (p *Pool[T]) GetWithReset() T
GetWithReset returns an item from the pool and applies the optional reset.
type PoolOption ¶ added in v0.8.3
PoolOption configures pool behavior.
func WithReset ¶ added in v0.8.3
func WithReset[T any](reset func(T) T) PoolOption[T]
WithReset configures a reset function applied by GetWithReset.
type SparseSet ¶ added in v0.6.0
type SparseSet[T any] struct { // contains filtered or unexported fields }
SparseSet is a growable, O(1) add/get/remove container that uses stable, generational handles to reference elements without exposing internal indices. Removals are constant time by swapping the last element into the removed slot in the dense array.
This is a Go port inspired by Karl Zylinski's odin-handle-map (handle_map_growing), adapted to Go generics and idioms.
The zero value is ready to use; use NewSparseSet to pre-reserve.
func NewSparseSet ¶ added in v0.6.0
NewSparseSet constructs a SparseSet with an optional initial slot capacity. A capacity of 0 creates an empty set with no pre-allocated slots.
func (*SparseSet[T]) Cap ¶ added in v0.6.0
Cap returns the number of total slots (live + free) that can be used without growing the sparse structures.
func (*SparseSet[T]) Clear ¶ added in v0.6.0
func (s *SparseSet[T]) Clear()
Clear removes all elements. Existing handles become invalid.
func (*SparseSet[T]) Contains ¶ added in v0.6.0
Contains reports whether h refers to a live element in s.
func (*SparseSet[T]) GetRef ¶ added in v0.6.0
GetRef returns a pointer to the value for h if valid. Note: Removing other elements may move the value due to swap-remove, invalidating previously taken pointers. Use only transiently.
func (*SparseSet[T]) Handles ¶ added in v0.6.0
Handles returns a snapshot of handles for all live elements.
func (*SparseSet[T]) Insert ¶ added in v0.6.0
Insert adds v to the set and returns a stable handle to it. Amortized O(1). May grow the internal storage.
func (*SparseSet[T]) Range ¶ added in v0.6.0
Range iterates over all live elements. The callback receives a current handle for each element and a pointer to its value. If f returns false, iteration stops early.
func (*SparseSet[T]) Remove ¶ added in v0.6.0
Remove deletes the element referenced by h if present. Returns true if the element existed and was removed.
func (*SparseSet[T]) Reserve ¶ added in v0.6.0
Reserve ensures the set can accommodate at least n live elements without reallocating dense storage. Note: this does not change the number of available slots for handles. To increase the number of potential handles without insertions, call ReserveSlots.
func (*SparseSet[T]) ReserveSlots ¶ added in v0.6.0
ReserveSlots ensures the set has at least n slots available to be populated by future Insert calls before growing the sparse structures.