Documentation ¶
Index ¶
- func Arrange[T any, O constraints.Ordered](elems []T, getKey func(T) O) []T
- func Delete[S ~[]E, E any](slice S, idxs ...int) S
- func DeleteBy[S ~[]E, E comparable](slice S, elems ...E) S
- func DeleteFunc[S ~[]E, E any](slice S, del func(E) bool) S
- func EveryNil(elems ...any) bool
- func Filter[S ~[]V, V any](slice S, predicate func(item V) bool) S
- func IndexAll[S ~[]E, E comparable](slice S, elem E) []int
- func IndexAllFunc[S ~[]E, E any](slice S, predicate func(E) bool) []int
- func IndexOf[T comparable](slice, sub []T) int
- func LastIndexOf[T comparable](slice, sub []T) int
- func Map[S ~[]T, T any, R any](slice S, iteratee func(item T) R) []R
- 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 Range[T constraints.Integer](elementNum uint) []T
- 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 Delete ¶ added in v1.0.54
Example ¶
package main import ( "fmt" "github.com/xuender/kit/los" ) func main() { fmt.Println(los.Delete([]int{0, 1, 2, 3, 4})) fmt.Println(los.Delete([]int{0, 1, 2, 3, 4}, 1)) fmt.Println(los.Delete([]int{0, 1, 2, 3, 4}, 3, 1)) fmt.Println(los.Delete([]int{0, 1, 2, 3, 4}, 3, 4)) fmt.Println(los.Delete([]int{0, 1, 2, 3, 4}, 2, 3)) fmt.Println(los.Delete([]int{0, 1, 2, 3, 4}, 0, 1)) fmt.Println(los.Delete([]int{0, 1, 2, 3, 4}, 0, 1, 2, 3, 4)) }
Output: [0 1 2 3 4] [0 2 3 4] [0 2 4] [0 1 2] [0 1 4] [2 3 4] []
func DeleteBy ¶ added in v1.0.54
func DeleteBy[S ~[]E, E comparable](slice S, elems ...E) S
Example ¶
package main import ( "fmt" "github.com/xuender/kit/los" ) func main() { fmt.Println(los.DeleteBy([]int{0, 1, 2, 3, 4}, 1)) }
Output: [0 2 3 4]
func DeleteFunc ¶ added in v1.0.54
Example ¶
package main import ( "fmt" "github.com/xuender/kit/los" ) func main() { fmt.Println(los.DeleteFunc([]int{0, 1, 2, 3, 4}, func(num int) bool { return num == 1 })) }
Output: [0 2 3 4]
func EveryNil ¶ added in v1.0.11
Example ¶
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 Filter ¶ added in v1.0.54
Example ¶
package main import ( "fmt" "github.com/xuender/kit/los" ) func main() { fmt.Println(los.Filter([]int{1, 2, 3, 4}, func(num int) bool { return num%2 == 0 })) }
Output: [2 4]
func IndexAll ¶ added in v1.0.54
func IndexAll[S ~[]E, E comparable](slice S, elem E) []int
Example ¶
package main import ( "fmt" "github.com/xuender/kit/los" ) func main() { fmt.Println(los.IndexAll([]int{1, 2, 3, 4, 3, 2, 1}, 1)) fmt.Println(los.IndexAll([]int{1, 2, 3, 4, 3, 2, 1}, 2)) fmt.Println(los.IndexAll([]int{1, 2, 3, 4, 3, 2, 1}, 4)) fmt.Println(los.IndexAll([]int{1, 2, 3, 4, 3, 2, 1}, 5)) }
Output: [0 6] [1 5] [3] []
func IndexAllFunc ¶ added in v1.0.54
Example ¶
package main import ( "fmt" "github.com/xuender/kit/los" ) func main() { fmt.Println(los.IndexAllFunc([]int{1, 2, 3, 4, 3, 2, 1}, func(num int) bool { return num == 1 })) fmt.Println(los.IndexAllFunc([]int{1, 2, 3, 4, 3, 2, 1}, func(num int) bool { return num == 2 })) fmt.Println(los.IndexAllFunc([]int{1, 2, 3, 4, 3, 2, 1}, func(num int) bool { return num == 4 })) fmt.Println(los.IndexAllFunc([]int{1, 2, 3, 4, 3, 2, 1}, func(num int) bool { return num == 5 })) }
Output: [0 6] [1 5] [3] []
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 Map ¶ added in v1.0.51
Example ¶
package main import ( "fmt" "github.com/xuender/kit/los" ) func main() { fmt.Println(los.Map([]int{1, 2, 3, 4}, func(item int) int { return item * 2 })) }
Output: [2 4 6 8]
func Range ¶ added in v1.0.54
func Range[T constraints.Integer](elementNum uint) []T
Example ¶
package main import ( "fmt" "github.com/xuender/kit/los" ) func main() { fmt.Println(los.Range[uint32](3)) }
Output: [0 1 2]
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 ¶
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 算法.
Click to show internal directories.
Click to hide internal directories.