Documentation ¶
Index ¶
- func Arrange[T any, O constraints.Ordered](elems []T, getKey func(T) O) []T
- func EveryNil(elems ...any) bool
- func IndexOf[T comparable](slice, sub []T) int
- func LastIndexOf[T comparable](slice, sub []T) int
- func Must[T any](val T, err error, messageArgs ...any) T
- func Must0(err error, messageArgs ...any)
- func Must1[T any](val T, err error, messageArgs ...any) T
- func Must2[T1, T2 any](val1 T1, val2 T2, err error, messageArgs ...any) (T1, T2)
- func Must3[T1, T2, T3 any](val1 T1, val2 T2, val3 T3, err error, messageArgs ...any) (T1, T2, T3)
- func Must4[T1, T2, T3, T4 any](val1 T1, val2 T2, val3 T3, val4 T4, err error, messageArgs ...any) (T1, T2, T3, T4)
- func Must5[T1, T2, T3, T4, T5 any](val1 T1, val2 T2, val3 T3, val4 T4, val5 T5, err error, messageArgs ...any) (T1, T2, T3, T4, T5)
- func Must6[T1, T2, T3, T4, T5, T6 any](val1 T1, val2 T2, val3 T3, val4 T4, val5 T5, val6 T6, err error, ...) (T1, T2, T3, T4, T5, T6)
- func Pull[V comparable](collection []V, elements ...V) []V
- func PullAt[V any](collection []V, indices ...int) []V
- func Remove[V comparable](collection []V, predicate func(V, int) bool) []V
- func SampleBool() bool
- func SomeNil(elems ...any) bool
- func Split[T comparable](collection []T, isSeparator func(T, int) bool) [][]T
- func SplitStr(str string, separators ...rune) []string
- type Sunday
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Arrange ¶ added in v1.0.28
func Arrange[T any, O constraints.Ordered](elems []T, getKey func(T) O) []T
Arrange 整理成员执行顺序,key相等的避免同时执行.
Example ¶
ExampleArrange is an example function.
package main import ( "fmt" "github.com/xuender/kit/los" ) func main() { fmt.Println(los.Arrange( []int{1, 1, 2, 2, 2, 3}, func(num int) int { return num }), ) }
Output: [2 1 3 2 1 2]
func EveryNil ¶ added in v1.0.11
Example ¶
ExampleEveryNil is an example function.
package main import ( "fmt" "github.com/xuender/kit/los" ) func main() { fmt.Println(los.EveryNil(nil, nil)) fmt.Println(los.EveryNil(nil, 1)) }
Output: true false
func IndexOf ¶ added in v1.0.31
func IndexOf[T comparable](slice, sub []T) int
Example ¶
package main import ( "fmt" "github.com/xuender/kit/los" ) func main() { slice := []int{1, 2, 1, 2} fmt.Println(los.IndexOf(slice, []int{2, 1})) fmt.Println(los.IndexOf(slice, []int{1, 2, 1})) fmt.Println(los.IndexOf(slice, []int{2, 1, 1})) fmt.Println(los.IndexOf(slice, []int{1, 2, 1, 2, 1})) fmt.Println(los.IndexOf(slice, []int{1, 2})) }
Output: 1 0 -1 -1 0
func LastIndexOf ¶ added in v1.0.31
func LastIndexOf[T comparable](slice, sub []T) int
Example ¶
package main import ( "fmt" "github.com/xuender/kit/los" ) func main() { slice := []int{1, 2, 1, 2} fmt.Println(los.LastIndexOf(slice, []int{2, 1})) fmt.Println(los.LastIndexOf(slice, []int{1, 2, 1})) fmt.Println(los.LastIndexOf(slice, []int{2, 1, 1})) fmt.Println(los.LastIndexOf(slice, []int{1, 2, 1, 2, 1})) fmt.Println(los.LastIndexOf(slice, []int{1, 2})) }
Output: 1 0 -1 -1 2
func Pull ¶
func Pull[V comparable](collection []V, elements ...V) []V
Pull 删除切片指定成员.
Example ¶
ExamplePull is an example function.
package main import ( "fmt" "github.com/xuender/kit/los" ) func main() { fmt.Println(los.Pull([]int{1, 2, 2, 3}, 0, 2)) }
Output: [1 3]
func PullAt ¶
PullAt 删除切片指定位置.
Example ¶
ExamplePullAt is an example function.
package main import ( "fmt" "github.com/xuender/kit/los" ) func main() { fmt.Println(los.PullAt([]rune{'1', '2', '2', '3'}, 2, 3)) }
Output: [49 50]
func Remove ¶
func Remove[V comparable](collection []V, predicate func(V, int) bool) []V
Remove 根据断言删除.
Example ¶
ExampleRemove is an example function.
package main import ( "fmt" "github.com/xuender/kit/los" ) func main() { fmt.Println(los.Remove([]int{1, 2, 2, 3, 4}, func(item, _ int) bool { return item%2 == 0 })) }
Output: [1 3]
func SampleBool ¶ added in v1.0.27
func SampleBool() bool
Example ¶
package main import ( "fmt" "math/rand" "github.com/xuender/kit/los" ) func main() { rand.Seed(3) fmt.Println(los.SampleBool()) fmt.Println(los.SampleBool()) }
Output: false true
func SomeNil ¶ added in v1.0.11
Example ¶
ExampleSomeNil is an example function.
package main import ( "fmt" "github.com/xuender/kit/los" ) func main() { fmt.Println(los.SomeNil(nil, 1)) fmt.Println(los.SomeNil(1, 2)) }
Output: true false
func Split ¶
func Split[T comparable](collection []T, isSeparator func(T, int) bool) [][]T
Split 切片分解.
Example ¶
ExampleSplit is an example function.
package main import ( "fmt" "github.com/xuender/kit/los" ) func main() { fmt.Println(los.Split( []int{1, 0, 2, 3, 0, 4, 0, 5}, func(num, _ int) bool { return num == 0 }, )) }
Output: [[1] [2 3] [4] [5]]
Types ¶
type Sunday ¶ added in v1.0.35
type Sunday[C comparable] struct { // contains filtered or unexported fields }
Sunday 算法数组查找.
func NewSunday ¶ added in v1.0.35
func NewSunday[C comparable](sub []C) *Sunday[C]
NewSunday 新建 Sunday 算法.
Source Files ¶
Click to show internal directories.
Click to hide internal directories.