diff --git a/README.md b/README.md index 09e4213..2d3f2a3 100644 --- a/README.md +++ b/README.md @@ -248,6 +248,8 @@ import "github.com/duke-git/lancet/v2/convertor" [[play](https://go.dev/play/p/zI6xsmuQRbn)] - **DeepClone** : creates a deep copy of passed item, can't clone unexported field of struct. [[doc](https://github.com/duke-git/lancet/blob/main/docs/convertor.md#DeepClone)] + [[play](https://go.dev/play/p/j4DP5dquxnk)] + ### 5. Cryptor package is for data encryption and decryption. @@ -836,13 +838,16 @@ import "github.com/duke-git/lancet/v2/slice" [[play](https://go.dev/play/p/pJ-d6MUWcvK)] - **Drop** : drop n elements from the start of a slice. [[doc](https://github.com/duke-git/lancet/blob/main/docs/slice.md#Drop)] - [[play](https://go.dev/play/p/pJ-d6MUWcvK)] + [[play](https://go.dev/play/p/jnPO2yQsT8H)] - **DropRight** : drop n elements from the end of a slice. [[doc](https://github.com/duke-git/lancet/blob/main/docs/slice.md#DropRight)] + [[play](https://go.dev/play/p/8bcXvywZezG)] - **DropWhile** : drop n elements from the start of a slice while predicate function returns true. [[doc](https://github.com/duke-git/lancet/blob/main/docs/slice.md#DropWhile)] + [[play](https://go.dev/play/p/4rt252UV_qs)] - **DropRightWhile** : drop n elements from the end of a slice while predicate function returns true. [[doc](https://github.com/duke-git/lancet/blob/main/docs/slice.md#DropRightWhile)] + [[play](https://go.dev/play/p/6wyK3zMY56e)] - **Equal** : checks if two slices are equal: the same length and all elements' order and value are equal. [[doc](https://github.com/duke-git/lancet/blob/main/docs/slice.md#Equal)] [[play](https://go.dev/play/p/WcRQJ37ifPa)] @@ -920,12 +925,16 @@ import "github.com/duke-git/lancet/v2/slice" [[play](https://go.dev/play/p/YHvhnWGU3Ge)] - **IsAscending** : Checks if a slice is ascending order. [[doc](https://github.com/duke-git/lancet/blob/main/docs/slice.md#IsAscending)] + [[play](https://go.dev/play/p/9CtsFjet4SH)] - **IsDescending** : Checks if a slice is descending order. [[doc](https://github.com/duke-git/lancet/blob/main/docs/slice.md#IsDescending)] + [[play](https://go.dev/play/p/U_LljFXma14)] - **IsSorted** : Checks if a slice is sorted (ascending or descending). [[doc](https://github.com/duke-git/lancet/blob/main/docs/slice.md#IsSorted)] + [[play](https://go.dev/play/p/nCE8wPLwSA-)] - **IsSortedByKey** : Checks if a slice is sorted by iteratee function. [[doc](https://github.com/duke-git/lancet/blob/main/docs/slice.md#IsSortedByKey)] + [[play](https://go.dev/play/p/tUoGB7DOHI4)] - **Sort** : sorts a slice of any ordered type(number or string). [[doc](https://github.com/duke-git/lancet/blob/main/docs/slice.md#Sort)] [[play](https://go.dev/play/p/V9AVjzf_4Fk)] diff --git a/README_zh-CN.md b/README_zh-CN.md index 36ec432..d14b66d 100644 --- a/README_zh-CN.md +++ b/README_zh-CN.md @@ -247,6 +247,8 @@ import "github.com/duke-git/lancet/v2/convertor" [[play](https://go.dev/play/p/zI6xsmuQRbn)] - **DeepClone** : 创建一个传入值的深拷贝, 无法克隆结构体的非导出字段。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/convertor_zh-CN.md#DeepClone)] + [[play](https://go.dev/play/p/j4DP5dquxnk)] + ### 5. cryptor 加密包支持数据加密和解密,获取 md5,hash 值。支持 base64, md5, hmac, aes, des, rsa。 @@ -844,13 +846,16 @@ import "github.com/duke-git/lancet/v2/slice" [[play](https://go.dev/play/p/pJ-d6MUWcvK)] - **Drop** : 从切片头部删除n个元素。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/slice_zh-CN.md#Drop)] - [[play](https://go.dev/play/p/pJ-d6MUWcvK)] + [[play](https://go.dev/play/p/jnPO2yQsT8H)] - **DropRight** : 从切片尾部删除n个元素。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/slice_zh-CN.md#DropRight)] + [[play](https://go.dev/play/p/8bcXvywZezG)] - **DropWhile** : 从切片的头部删除n个元素,这个n个元素满足predicate函数返回true。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/slice_zh-CN.md#DropWhile)] + [[play](https://go.dev/play/p/4rt252UV_qs)] - **DropRightWhile** : 从切片的尾部删除n个元素,这个n个元素满足predicate函数返回true。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/slice_zh-CN.md#DropRightWhile)] + [[play](https://go.dev/play/p/6wyK3zMY56e)] - **Equal** : 检查两个切片是否相等,相等条件:切片长度相同,元素顺序和值都相同。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/slice_zh-CN.md#Equal)] [[play](https://go.dev/play/p/WcRQJ37ifPa)] @@ -928,12 +933,16 @@ import "github.com/duke-git/lancet/v2/slice" [[play](https://go.dev/play/p/YHvhnWGU3Ge)] - **IsAscending** : 检查切片元素是否按升序排列。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/slice_zh-CN.md#IsAscending)] + [[play](https://go.dev/play/p/9CtsFjet4SH)] - **IsDescending** : 检查切片元素是否按降序排列。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/slice_zh-CN.md#IsDescending)] + [[play](https://go.dev/play/p/U_LljFXma14)] - **IsSorted** : 检查切片元素是否是有序的(升序或降序)。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/slice_zh-CN.md#IsSorted)] + [[play](https://go.dev/play/p/nCE8wPLwSA-)] - **IsSortedByKey** : 通过iteratee函数,检查切片元素是否是有序的。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/slice_zh-CN.md#IsSortedByKey)] + [[play](https://go.dev/play/p/tUoGB7DOHI4)] - **Sort** : 对任何有序类型(数字或字符串)的切片进行排序,使用快速排序算法。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/slice_zh-CN.md#Sort)] [[play](https://go.dev/play/p/V9AVjzf_4Fk)] diff --git a/convertor/convertor.go b/convertor/convertor.go index 2aae431..a6a229b 100644 --- a/convertor/convertor.go +++ b/convertor/convertor.go @@ -327,7 +327,7 @@ func DecodeByte(data []byte, target any) error { // DeepClone creates a deep copy of passed item. // can't clone unexported field of struct -// Play: todo +// Play: https://go.dev/play/p/j4DP5dquxnk func DeepClone[T any](src T) T { c := cloner{ ptrs: map[reflect.Type]map[uintptr]reflect.Value{}, diff --git a/slice/slice.go b/slice/slice.go index 980fc89..dca073c 100644 --- a/slice/slice.go +++ b/slice/slice.go @@ -559,7 +559,7 @@ func DeleteAt[T any](slice []T, start int, end ...int) []T { } // Drop drop n elements from the start of a slice. -// Play: https://go.dev/play/p/pJ-d6MUWcvK +// Play: https://go.dev/play/p/jnPO2yQsT8H func Drop[T any](slice []T, n int) []T { size := len(slice) @@ -577,7 +577,7 @@ func Drop[T any](slice []T, n int) []T { } // DropRight drop n elements from the end of a slice. -// Play: todo +// Play: https://go.dev/play/p/8bcXvywZezG func DropRight[T any](slice []T, n int) []T { size := len(slice) @@ -595,7 +595,7 @@ func DropRight[T any](slice []T, n int) []T { } // DropWhile drop n elements from the start of a slice while predicate function returns true. -// Play: todo +// Play: https://go.dev/play/p/4rt252UV_qs func DropWhile[T any](slice []T, predicate func(item T) bool) []T { i := 0 @@ -611,7 +611,7 @@ func DropWhile[T any](slice []T, predicate func(item T) bool) []T { } // DropRightWhile drop n elements from the end of a slice while predicate function returns true. -// Play: todo +// Play: https://go.dev/play/p/6wyK3zMY56e func DropRightWhile[T any](slice []T, predicate func(item T) bool) []T { i := len(slice) - 1 @@ -831,7 +831,7 @@ func Shuffle[T any](slice []T) []T { } // IsAscending checks if a slice is ascending order. -// Play: todo +// Play: https://go.dev/play/p/9CtsFjet4SH func IsAscending[T constraints.Ordered](slice []T) bool { for i := 1; i < len(slice); i++ { if slice[i-1] > slice[i] { @@ -843,7 +843,7 @@ func IsAscending[T constraints.Ordered](slice []T) bool { } // IsDescending checks if a slice is descending order. -// Play: todo +// Play: https://go.dev/play/p/U_LljFXma14 func IsDescending[T constraints.Ordered](slice []T) bool { for i := 1; i < len(slice); i++ { if slice[i-1] < slice[i] { @@ -855,13 +855,13 @@ func IsDescending[T constraints.Ordered](slice []T) bool { } // IsSorted checks if a slice is sorted(ascending or descending). -// Play: todo +// Play: https://go.dev/play/p/nCE8wPLwSA- func IsSorted[T constraints.Ordered](slice []T) bool { return IsAscending(slice) || IsDescending(slice) } // IsSortedByKey checks if a slice is sorted by iteratee function. -// Play: todo +// Play: https://go.dev/play/p/tUoGB7DOHI4 func IsSortedByKey[T any, K constraints.Ordered](slice []T, iteratee func(item T) K) bool { size := len(slice)