utils

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendIfUnique

func AppendIfUnique[T comparable](slice []T, element T) []T

func Coalesce

func Coalesce[T *U, U any](a T, b T) T

Returns `a` if `a` is not `nil`; Otherwise, returns `b`. Coalesce is roughly analogous to `??` in JS, except that it non-shortcutting, so it is advised to only use a constant or precomputed value for `b`

func Concatenate

func Concatenate[T any](s1 []T, s2 []T) []T

func CountWhere

func CountWhere[T any](slice []T, f func(T) bool) int

func ElementOrNil

func ElementOrNil[T any](slice []T, index int) T

func Every

func Every[T any](slice []T, f func(T) bool) bool

func ExecuteCommand

func ExecuteCommand(cmd string) error

func Filter

func Filter[T any](slice []T, f func(T) bool) []T

func FilterIndex

func FilterIndex[T any](slice []T, f func(T, int, []T) bool) []T

func Find

func Find[T any](slice []T, f func(T) bool) T

func FindIndex

func FindIndex[T any](slice []T, f func(T) bool) int

func FindLast

func FindLast[T any](slice []T, f func(T) bool) T

func FindLastIndex

func FindLastIndex[T any](slice []T, f func(T) bool) int

func FirstNonNil

func FirstNonNil[T any, U comparable](slice []T, f func(T) U) U

func FirstOrNil

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

func FirstOrNilSeq

func FirstOrNilSeq[T any](seq iter.Seq[T]) T

func FlatMap

func FlatMap[T any, U comparable](slice []T, f func(T) []U) []U

func Flatten

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

func GetAgeByBirthday

func GetAgeByBirthday(birthday string) int

GetAgeByBirthday 根据生日计算年龄, 生日格式 yyyy-MM-dd

func GetPinyin

func GetPinyin(s string) string

func GetPinyinFirstLetter

func GetPinyinFirstLetter(s string) string

func IfElse

func IfElse[T any](b bool, whenTrue T, whenFalse T) T

Returns whenTrue if b is true; otherwise, returns whenFalse. IfElse should only be used when branches are either constant or precomputed as both branches will be evaluated regardless as to the value of b.

func InsertSorted

func InsertSorted[T any](slice []T, element T, cmp func(T, T) int) []T

func LastOrNil

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

func Map

func Map[T, U any](slice []T, f func(T) U) []U

func MapFiltered

func MapFiltered[T any, U any](slice []T, f func(T) (U, bool)) []U

func MapIndex

func MapIndex[T, U any](slice []T, f func(T, int) U) []U

func MapNonNil

func MapNonNil[T any, U comparable](slice []T, f func(T) U) []U

func Memoize

func Memoize[T any](create func() T) func() T

func Must

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

func Or

func Or[T any](funcs ...func(T) bool) func(T) bool

func OrElse

func OrElse[T comparable](value T, defaultValue T) T

Returns value if value is not the zero value of T; Otherwise, returns defaultValue. OrElse should only be used when defaultValue is constant or precomputed as its argument will be evaluated regardless as to the content of value.

func ReplaceElement

func ReplaceElement[T any](slice []T, i int, t T) []T

func Same

func Same[T any](s1 []T, s2 []T) bool

func SameMap

func SameMap[T comparable](slice []T, f func(T) T) []T

func SameMapIndex

func SameMapIndex[T comparable](slice []T, f func(T, int) T) []T

func Some

func Some[T any](slice []T, f func(T) bool) bool

func Splice

func Splice[T any](s1 []T, start int, deleteCount int, items ...T) []T

func TryMap

func TryMap[T, U any](slice []T, f func(T) (U, error)) ([]U, error)

Types

This section is empty.

Jump to

Keyboard shortcuts

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