1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-04 21:02:27 +08:00

update go playground demo

This commit is contained in:
dudaodong
2023-02-16 14:10:24 +08:00
parent 8bf0786abe
commit ca9ecb9c8a
4 changed files with 29 additions and 11 deletions

View File

@@ -248,6 +248,8 @@ import "github.com/duke-git/lancet/v2/convertor"
[[play](https://go.dev/play/p/zI6xsmuQRbn)]
- **<big>DeepClone</big>** : 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)]
- **<big>Drop</big>** : 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)]
- **<big>DropRight</big>** : 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)]
- **<big>DropWhile</big>** : 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)]
- **<big>DropRightWhile</big>** : 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)]
- **<big>Equal</big>** : 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)]
- **<big>IsAscending</big>** : 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)]
- **<big>IsDescending</big>** : 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)]
- **<big>IsSorted</big>** : 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-)]
- **<big>IsSortedByKey</big>** : 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)]
- **<big>Sort</big>** : 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)]

View File

@@ -247,6 +247,8 @@ import "github.com/duke-git/lancet/v2/convertor"
[[play](https://go.dev/play/p/zI6xsmuQRbn)]
- **<big>DeepClone</big>** : 创建一个传入值的深拷贝, 无法克隆结构体的非导出字段。
[[doc](https://github.com/duke-git/lancet/blob/main/docs/convertor_zh-CN.md#DeepClone)]
[[play](https://go.dev/play/p/j4DP5dquxnk)]
### 5. cryptor 加密包支持数据加密和解密,获取 md5hash 值。支持 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)]
- **<big>Drop</big>** : 从切片头部删除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)]
- **<big>DropRight</big>** : 从切片尾部删除n个元素。
[[doc](https://github.com/duke-git/lancet/blob/main/docs/slice_zh-CN.md#DropRight)]
[[play](https://go.dev/play/p/8bcXvywZezG)]
- **<big>DropWhile</big>** : 从切片的头部删除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)]
- **<big>DropRightWhile</big>** : 从切片的尾部删除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)]
- **<big>Equal</big>** : 检查两个切片是否相等,相等条件:切片长度相同,元素顺序和值都相同。
[[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)]
- **<big>IsAscending</big>** : 检查切片元素是否按升序排列。
[[doc](https://github.com/duke-git/lancet/blob/main/docs/slice_zh-CN.md#IsAscending)]
[[play](https://go.dev/play/p/9CtsFjet4SH)]
- **<big>IsDescending</big>** : 检查切片元素是否按降序排列。
[[doc](https://github.com/duke-git/lancet/blob/main/docs/slice_zh-CN.md#IsDescending)]
[[play](https://go.dev/play/p/U_LljFXma14)]
- **<big>IsSorted</big>** : 检查切片元素是否是有序的(升序或降序)。
[[doc](https://github.com/duke-git/lancet/blob/main/docs/slice_zh-CN.md#IsSorted)]
[[play](https://go.dev/play/p/nCE8wPLwSA-)]
- **<big>IsSortedByKey</big>** : 通过iteratee函数检查切片元素是否是有序的。
[[doc](https://github.com/duke-git/lancet/blob/main/docs/slice_zh-CN.md#IsSortedByKey)]
[[play](https://go.dev/play/p/tUoGB7DOHI4)]
- **<big>Sort</big>** : 对任何有序类型(数字或字符串)的切片进行排序,使用快速排序算法。
[[doc](https://github.com/duke-git/lancet/blob/main/docs/slice_zh-CN.md#Sort)]
[[play](https://go.dev/play/p/V9AVjzf_4Fk)]

View File

@@ -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{},

View File

@@ -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)