Documentation
¶
Overview ¶
Package typeutil provides convenience utilities for working with go types
Primarily, consists of useful extensions over collections, primitives and iterators
Index ¶
- func Ceil[T numeric](x float64) T
- func ChanSeq[T any](seq iter.Seq[T]) <-chan T
- func ChanSeqSized[T any](seq iter.Seq[T], size int) <-chan T
- func ChanSlice[T any](vs []T) <-chan T
- func Chunk[T any](s []T, chunkSize int) [][]T
- func CopySeq[T any](seq iter.Seq[T]) (iter.Seq[T], iter.Seq[T])
- func DaysIn(m time.Month, year int) int
- func DeduplicateSeq[T comparable](seq iter.Seq[T]) iter.Seq[T]
- func DivUp[T numeric](x, y T) T
- func EndOfDay(t time.Time) time.Time
- func FirstOfMonth(t time.Time) time.Time
- func IsWeekday(t time.Time) bool
- func LastOfMonth(t time.Time) time.Time
- func Map[T any, U any](seq iter.Seq[T], fn func(T) U) iter.Seq[U]
- func SafeSlice[T any](x []T) []T
- func Sorted[K cmp.Ordered, V any](m map[K]V) map[K]V
- func Timestamp(t time.Time) int64
- func TruncateString(s string, limit int) string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Ceil ¶ added in v1.0.1
func Ceil[T numeric](x float64) T
Ceil returns the least integer value greater than or equal to x, casted to type T.
func ChanSeq ¶
ChanSeq accepts iterator sequence and returns the channel representation of it.
Keep in mind that the channel is unbuffered, so can lead to deadlocks if routine is unable to read from it due to external locks.
func ChanSeqSized ¶ added in v1.0.4
ChanSeqSized accepts iterator sequence and channel size, and returns the channel representation of iterator.
func ChanSlice ¶
func ChanSlice[T any](vs []T) <-chan T
ChanSlice creates a read-only channel with values from provided slice.
func Chunk ¶
Chunk returns a slice of chunks of original slice. All chunks except the last one are of size chunkSize.
func DeduplicateSeq ¶
func DeduplicateSeq[T comparable](seq iter.Seq[T]) iter.Seq[T]
DeduplicateSeq accepts iterator sequence, and returns unique values sequence.
func DivUp ¶ added in v1.0.1
func DivUp[T numeric](x, y T) T
DivUp divides x, y (converted to float64 for accuracy first), then applies Ceil on top.
func FirstOfMonth ¶
FirstOfMonth returns the first instant of the month in current location.
func IsWeekday ¶
IsWeekday returns if the specified time is within standard week days (time.Monday through time.Friday including).
func LastOfMonth ¶
LastOfMonth returns the last instant of month in current location.
func SafeSlice ¶
func SafeSlice[T any](x []T) []T
SafeSlice returns always non-nil slice of T
Useful to return in DTOs or functions which results are relied upon during marshaling.
func Timestamp ¶
Timestamp converts time.Time to unix timestamp. if time.Time is a zero time, returned value is 0 (zeroish return).
func TruncateString ¶
TruncateString returns at most limit characters of provided string.
Types ¶
This section is empty.