Documentation
¶
Index ¶
- func AppendIfUnique[T comparable](slice []T, element T) []T
- func Coalesce[T *U, U any](a T, b T) T
- func Concatenate[T any](s1 []T, s2 []T) []T
- func CountWhere[T any](slice []T, f func(T) bool) int
- func ElementOrNil[T any](slice []T, index int) T
- func Every[T any](slice []T, f func(T) bool) bool
- func ExecuteCommand(cmd string) error
- func Filter[T any](slice []T, f func(T) bool) []T
- func FilterIndex[T any](slice []T, f func(T, int, []T) bool) []T
- func Find[T any](slice []T, f func(T) bool) T
- func FindIndex[T any](slice []T, f func(T) bool) int
- func FindLast[T any](slice []T, f func(T) bool) T
- func FindLastIndex[T any](slice []T, f func(T) bool) int
- func FirstNonNil[T any, U comparable](slice []T, f func(T) U) U
- func FirstOrNil[T any](slice []T) T
- func FirstOrNilSeq[T any](seq iter.Seq[T]) T
- func FlatMap[T any, U comparable](slice []T, f func(T) []U) []U
- func Flatten[T any](array [][]T) []T
- func GetAgeByBirthday(birthday string) int
- func GetPinyin(s string) string
- func GetPinyinFirstLetter(s string) string
- func IfElse[T any](b bool, whenTrue T, whenFalse T) T
- func InsertSorted[T any](slice []T, element T, cmp func(T, T) int) []T
- func LastOrNil[T any](slice []T) T
- func Map[T, U any](slice []T, f func(T) U) []U
- func MapFiltered[T any, U any](slice []T, f func(T) (U, bool)) []U
- func MapIndex[T, U any](slice []T, f func(T, int) U) []U
- func MapNonNil[T any, U comparable](slice []T, f func(T) U) []U
- func Memoize[T any](create func() T) func() T
- func Must[T any](v T, err error) T
- func Or[T any](funcs ...func(T) bool) func(T) bool
- func OrElse[T comparable](value T, defaultValue T) T
- func ReplaceElement[T any](slice []T, i int, t T) []T
- func Same[T any](s1 []T, s2 []T) bool
- func SameMap[T comparable](slice []T, f func(T) T) []T
- func SameMapIndex[T comparable](slice []T, f func(T, int) T) []T
- func Some[T any](slice []T, f func(T) bool) bool
- func Splice[T any](s1 []T, start int, deleteCount int, items ...T) []T
- func TryMap[T, U any](slice []T, f func(T) (U, error)) ([]U, error)
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 ElementOrNil ¶
func ExecuteCommand ¶
func FilterIndex ¶
func FindLastIndex ¶
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 FlatMap ¶
func FlatMap[T any, U comparable](slice []T, f func(T) []U) []U
func GetAgeByBirthday ¶
GetAgeByBirthday 根据生日计算年龄, 生日格式 yyyy-MM-dd
func GetPinyinFirstLetter ¶
func IfElse ¶
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 MapFiltered ¶
func MapNonNil ¶
func MapNonNil[T any, U comparable](slice []T, f func(T) U) []U
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 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
Types ¶
This section is empty.