util

package
v0.0.0-...-33dae29 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const Day time.Duration = 24 * time.Hour

Variables

View Source
var ErrNotFound = errors.New("not found")

Functions

func AsMap

func AsMap[T any, K comparable](slice []T, keyGetter Mapper[T, K]) map[K]T

func AsSet

func AsSet[T any, K comparable](slice []T, keyGetter Mapper[T, K]) map[K]bool

func ByteCountSI

func ByteCountSI(b int64) string

func Chunk

func Chunk[T any](slice []T, size int) [][]T

Chunk batches []T into [][]T in groups of size. The final chunk of []T will be smaller than size if the input slice cannot be chunked evenly. It does not make any copies of slice elements.

As an example, take a slice of 5 integers and create chunks of 2 integers each (the final value creates a short chunk):

slices.Chunk([]int{1, 2, 3, 4, 5}, 2) = [][]int{{1, 2}, {3, 4}, {5}}

func Copy

func Copy[T any](t T) T

func DebugPrintJson

func DebugPrintJson(x ...interface{})

func DebugPrintYaml

func DebugPrintYaml(x interface{})

func Distinct

func Distinct[T comparable](data []T) []T

func Exists

func Exists[T any](slice []T, finder Predicate[T]) bool

func FilterSlice

func FilterSlice[T any](slice []T, predicate Predicate[T]) []T

func GroupByProperty

func GroupByProperty[T any, K comparable](items []T, getProperty func(T) K) map[K][]T

func Keys

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

func LogSymbol

func LogSymbol(coin, altCoin string) string

func Map

func Map[T, V any](slice []T, mapper Mapper[T, V]) []V

func Symbol

func Symbol(coin, altCoin string) string

func ToASCIITable

func ToASCIITable[T any](data []T, headers []string, footer []string, columns func(T) []string, opts ...ASCIITableOption) string

func ToJSON

func ToJSON(x interface{}) string

func ToYAML

func ToYAML(x interface{}) string

func Unsymbol

func Unsymbol(symbol string, referentialCoins, altCoins []string) (string, string, error)

func Values

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

func WrapPtr

func WrapPtr[T any](t T) *T

Types

type ASCIITableOption

type ASCIITableOption func(*tablewriter.Table)

type Mapper

type Mapper[T, K any] func(T) K

func Identity

func Identity[T any]() Mapper[T, T]

type Predicate

type Predicate[T any] Mapper[T, bool]

Jump to

Keyboard shortcuts

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