util

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: May 24, 2022 License: MIT Imports: 9 Imported by: 0

README

util

Miscellany of commons used in TCG projects.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Between

func Between[T constraints.Ordered](v, lower, upper T) bool

Between returns true if x >= lower and x <= upper.

func NN

func NN(x, y float64) float64

NN (Not Number) returns y if x is NaN or Inf.

func NNZ

func NNZ(x, y float64) float64

NNZ (Not Number or Zero) returns y if x is NaN or Inf or Zero.

func Round2DP

func Round2DP(x float64) float64

Round2DP rounds x to 2 decimal places.

func RoundTo

func RoundTo(x, y float64) float64

RoundTo rounds x to the nearest y precision.

func ToFloat

func ToFloat(v any) float64

ToFloat converts int or int64 to float64.

func ToInt

func ToInt(v any) int

ToInt converts int64 or float64 to int.

func ToString

func ToString(v any) string

ToString converts any to string (equivalent to fmt.Sprint).

func WriteToCSV

func WriteToCSV(filename string, data interface{}, encoder ...any) error

WriteToCSV writes the given data to a CSV file, optionally using the given encoders to custom marshal specific types. Will write a header row if the given file is empty. Wraps github.com/jszwec/csvutil

Types

type CSVEncoder

type CSVEncoder[T any] func(t T) ([]byte, error)

CSVEncoder is a custom encoder for marhsalling types to CSV files.

type ID

type ID string

ID is a unique identifier. Intended to wrap a ULID which is lexicographically sortable.

func NewID

func NewID() ID

NewID returns a new ID with seed as time now.

func NewIDWithTime

func NewIDWithTime(t time.Time) ID

NewIDWithTime returns a new ID with the given time as a seed.

Jump to

Keyboard shortcuts

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