util

package
v2.0.3 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const ApisenseTimeFormat = "2006-01-02T15-04-05.000Z"

ApisenseTimeFormat is the go time format representation of ApisenseTime

Variables

This section is empty.

Functions

func All

func All[T any](s []T, f func(T) bool) bool

All returns whether all elements in the given slice match the given predicate

func Any

func Any[T any](s []T, f func(T) bool) bool

Any returns whether any element in the given slice matches the given predicate

func Capitalize

func Capitalize(s string) string

Capitalize coverts the first char in the string to uppercase

func Contains

func Contains[T comparable](s []T, v T) bool

Contains returns whether the given slice contains the given element

func Exists

func Exists(path string) bool

Exists returns true if the given file exists

func ExpandHome

func ExpandHome(path *string)

ExpandHome replaes the character "~" in the string with the content of the "HOME" environment variable in place

func FindFirst

func FindFirst[T any](s []T, f func(T) bool) *T

FindFirst return a reference to the first element of the slice that matches the predicate. It returns nil if the slice is nil or empty or if no item matches the predicate.

func FirstOrDefault

func FirstOrDefault[T any](arr []T, fallback T) T

FirstOrDefault returns the first value in arr if it has items else fallback

func Keys

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

Keys returns the keys of a map in a non-deterministic fashion

func Map

func Map[TIn any, TOut any](s []TIn, f func(TIn) TOut) []TOut

Map maps the sequence of items to another using the given transformer function

func Max

func Max(arr []int) int

Max returns the max in a slice of integers

func Pad

func Pad(s string, maxLen int) string

Pad pads the string s to maxLen with spaces

func Transpose

func Transpose[T any](slice [][]T) [][]T

Transpose returns the matrix transposed from (nxm) to (mxn)

func Values

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

Values returns the values of a map in non-deterministic fashion

func Where

func Where[T any](s []T, f func(T) bool) []T

Where returns all elements in a slice that match the given predicate

Types

type ApisenseTime

type ApisenseTime time.Time

ApisenseTime is the time format used in everything apisense

func ParseTime

func ParseTime(s string) (ApisenseTime, error)

ParseTime parses a string into an ApisenseTime according to ApisenseTimeFormat

func (ApisenseTime) MarshalJSON

func (t ApisenseTime) MarshalJSON() ([]byte, error)

func (ApisenseTime) String

func (t ApisenseTime) String() string

String returns the formatted representation according to ApisenseTimeFormat

func (*ApisenseTime) UnmarshalJSON

func (t *ApisenseTime) UnmarshalJSON(b []byte) error

Jump to

Keyboard shortcuts

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