lod

package
v0.0.0-...-2040d2c Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ParseByte   = mkParseUint[byte](8)
	ParseUint8  = mkParseUint[uint8](8)
	ParseUint16 = mkParseUint[uint16](16)
	ParseUint32 = mkParseUint[uint32](32)
	ParseUint64 = mkParseUint[uint64](64)

	ParseInt8  = mkParseInt[int8](8)
	ParseInt16 = mkParseInt[int16](16)
	ParseInt32 = mkParseInt[int32](32)
	ParseInt64 = mkParseInt[int64](64)

	ParseFloat32 = mkParseFloat[float32](32)
	ParseFloat64 = mkParseFloat[float64](64)
)

Functions

func Array

func Array[T any](items ...T) []T

Array creates a slice from the given items.

func At

func At[T any](vs []T, i int, fallback ...T) (out T)

At 返回指定索引的值

func Atoi

func Atoi[T Number](in string) (out T, err error)

Atoi converts a number or bool to string

func CompareChain

func CompareChain[T any](compares ...func(a, b T) int) func(a, b T) int

CompareChain creates a compare function from the given compare functions.

func ErrDebug

func ErrDebug(err error) slog.Level

ErrDebug 返回日志级别,如果err不为零,返回 slog.LevelDebug,否则返回 slog.LevelInfo

func ErrInfo

func ErrInfo(err error) slog.Level

ErrInfo 返回日志级别,如果err不为零,返回 slog.LevelInfo,否则返回 slog.LevelInfo

func Filter

func Filter[S ~[]I, I any, F func(I) bool | func(I, int) bool](s S, f F) (r S)

Filter returns a new slice of the passed in slice, applying the passed in function to each item.

func First

func First[T any](vs []T, fallback ...T) (out T)

First 返回第一个值

func Flatten

func Flatten[T any](s [][]T) []T

Flatten returns a new slice concatenating the passed in slices.

func ForEach

func ForEach[I any, F func(I) | func(I, int) | func(I) bool | func(I, int) bool](s []I, f F)

ForEach iterates over the passed in slices and calls the passed in function.

func FormatInt

func FormatInt[T Int | Uint](in T, base ...int) string

func Iif

func Iif[T any](cond bool, t, f T) T

Iif 三元运算

func IifF

func IifF[T any](cond bool, t, f func() T) (out T)

IifF 三元运算

func Itoa

func Itoa[T Number | ~bool](in T) string

Itoa converts a number or bool to string

func Last

func Last[T any](vs []T, fallback ...T) (out T)

Last 返回最后一个值

func Map

func Map[I any, O any, F func(I) O | func(I, int) O | func(I) (O, bool) | func(I, int) (O, bool)](s []I, f F) (r []O)

Map returns a new slice of the passed in slice, applying the passed in function to each item.

func May

func May[T any](v T, _ error) T

May creates a function that ignores the error.

func Must

func Must[T any](v T, err error) T

Must panics if the error is not nil.

func Select

func Select[T comparable](vs ...T) (out T)

Select 选择第一个不为零值的值

func Selects

func Selects[T comparable](vs []T, fallback ...T) (out T)

Selects 选择第一个不为零值的值

Types

type Float

type Float interface {
	~float32 | ~float64
}

type IfElse

type IfElse[T any] func() T

func If

func If[T any](c bool, v T) IfElse[T]

func IfF

func IfF[T any](c bool, v func() T) IfElse[T]

func (IfElse[T]) Else

func (i IfElse[T]) Else(v T) T

func (IfElse[T]) ElseF

func (i IfElse[T]) ElseF(v func() T) T

func (IfElse[T]) ElseIf

func (i IfElse[T]) ElseIf(c bool, v T) IfElse[T]

func (IfElse[T]) ElseIfF

func (i IfElse[T]) ElseIfF(c bool, v func() T) IfElse[T]

type Int

type Int interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64
}

type Integer

type Integer interface {
	Int | Uint
}

type Number

type Number interface {
	Int | Uint | Float
}

type Uint

type Uint interface {
	~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
}

Jump to

Keyboard shortcuts

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