diff --git a/README.md b/README.md index 320c483..36aa0c8 100644 --- a/README.md +++ b/README.md @@ -397,6 +397,9 @@ import "github.com/duke-git/lancet/v2/cryptor" - **HmacSha512** : return the hmac hash of string use sha512. [[doc](https://github.com/duke-git/lancet/blob/main/docs/cryptor.md#HmacSha512)] [[play](https://go.dev/play/p/59Od6m4A0Ud)] +- **Md5Byte** : return the md5 string of byte slice. + [[doc](https://github.com/duke-git/lancet/blob/main/docs/cryptor.md#Md5Byte)] + [[play](https://go.dev/play/p/suraalH8lyC)] - **Md5String** : return the md5 value of string. [[doc](https://github.com/duke-git/lancet/blob/main/docs/cryptor.md#Md5String)] [[play](https://go.dev/play/p/1bLcVetbTOI)] @@ -486,6 +489,12 @@ import "github.com/duke-git/lancet/v2/datetime" - **GetNowDateTime** : return format yyyy-mm-dd hh-mm-ss of current datetime. [[doc](https://github.com/duke-git/lancet/blob/main/docs/datetime.md#GetNowDateTime)] [[play](https://go.dev/play/p/pI4AqngD0al)] +- **GetTodayStartTime** : return the start time of today, format: yyyy-mm-dd 00:00:00. + [[doc](https://github.com/duke-git/lancet/blob/main/docs/datetime.md#GetTodayStartTime)] + [[play](https://go.dev/play/p/84siyYF7t99)] +- **GetTodayEndTime** : return the end time of today, format: yyyy-mm-dd 23:59:59. + [[doc](https://github.com/duke-git/lancet/blob/main/docs/datetime.md#GetTodayEndTime)] + [[play](https://go.dev/play/p/jjrLnfoqgn3)] - **GetZeroHourTimestamp** : return timestamp of zero hour (timestamp of 00:00). [[doc](https://github.com/duke-git/lancet/blob/main/docs/datetime.md#GetZeroHourTimestamp)] [[play](https://go.dev/play/p/QmL2oIaGE3q)] @@ -1517,76 +1526,112 @@ import "github.com/duke-git/lancet/v2/tuple" - **Tuple2** : represents a 2 elemnets tuple. [[doc](https://github.com/duke-git/lancet/blob/main/docs/tuple.md#Tuple2)] + [[play](https://go.dev/play/p/3sHVqBQpLYN)] - **Tuple2_Unbox** : returns values in Tuple2. [[doc](https://github.com/duke-git/lancet/blob/main/docs/tuple.md#Tuple2_Unbox)] + [[play](https://go.dev/play/p/0fD1qfCVwjm)] - **Zip2** : create a slice of Tuple2, whose elements are correspond to the given slice elements. [[doc](https://github.com/duke-git/lancet/blob/main/docs/tuple.md#Zip2)] + [[play](https://go.dev/play/p/4ncWJJ77Xio)] - **Unzip2** : create a group of slice from a slice of Tuple2. [[doc](https://github.com/duke-git/lancet/blob/main/docs/tuple.md#Unzip2)] + [[play](https://go.dev/play/p/KBecr60feXb)] - **Tuple3** : represents a 3 elemnets tuple. [[doc](https://github.com/duke-git/lancet/blob/main/docs/tuple.md#Tuple3)] + [[play](https://go.dev/play/p/FtH2sdCLlCf)] - **Tuple3_Unbox** : returns values in Tuple3. [[doc](https://github.com/duke-git/lancet/blob/main/docs/tuple.md#Tuple3_Unbox)] + [[play](https://go.dev/play/p/YojLy-id1BS)] - **Zip3** : create a slice of Tuple3, whose elements are correspond to the given slice elements. [[doc](https://github.com/duke-git/lancet/blob/main/docs/tuple.md#Zip3)] + [[play](https://go.dev/play/p/97NgmsTILfu)] - **Unzip3** : create a group of slice from a slice of Tuple3. [[doc](https://github.com/duke-git/lancet/blob/main/docs/tuple.md#Unzip3)] + [[play](https://go.dev/play/p/bba4cpAa7KO)] - **Tuple4** : represents a 4 elemnets tuple. [[doc](https://github.com/duke-git/lancet/blob/main/docs/tuple.md#Tuple4)] + [[play](https://go.dev/play/p/D2EqDz096tk)] - **Tuple4_Unbox** : returns values in Tuple4. [[doc](https://github.com/duke-git/lancet/blob/main/docs/tuple.md#Tuple4_Unbox)] + [[play](https://go.dev/play/p/ACj9YuACGgW)] - **Zip4** : create a slice of Tuple4, whose elements are correspond to the given slice elements. [[doc](https://github.com/duke-git/lancet/blob/main/docs/tuple.md#Zip4)] + [[play](https://go.dev/play/p/PEmTYVK5hL4)] - **Unzip4** : create a group of slice from a slice of Tuple4. [[doc](https://github.com/duke-git/lancet/blob/main/docs/tuple.md#Unzip4)] + [[play](https://go.dev/play/p/rb8z4gyYSRN)] - **Tuple5** : represents a 5 elemnets tuple. [[doc](https://github.com/duke-git/lancet/blob/main/docs/tuple.md#Tuple5)] + [[play](https://go.dev/play/p/2WndmVxPg-r)] - **Tuple5_Unbox** : returns values in Tuple4. [[doc](https://github.com/duke-git/lancet/blob/main/docs/tuple.md#Tuple5_Unbox)] + [[play](https://go.dev/play/p/GyIyZHjCvoS)] - **Zip5** : create a slice of Tuple5, whose elements are correspond to the given slice elements. [[doc](https://github.com/duke-git/lancet/blob/main/docs/tuple.md#Zip5)] + [[play](https://go.dev/play/p/fCAAJLMfBIP)] - **Unzip5** : create a group of slice from a slice of Tuple5. [[doc](https://github.com/duke-git/lancet/blob/main/docs/tuple.md#Unzip5)] + [[play](https://go.dev/play/p/gyl6vKfhqPb)] - **Tuple6** : represents a 6 elemnets tuple. [[doc](https://github.com/duke-git/lancet/blob/main/docs/tuple.md#Tuple6)] + [[play](https://go.dev/play/p/VjqcCwEJZbs)] - **Tuple6_Unbox** : returns values in Tuple6. [[doc](https://github.com/duke-git/lancet/blob/main/docs/tuple.md#Tuple6_Unbox)] + [[play](https://go.dev/play/p/FjIHV7lpxmW)] - **Zip6** : create a slice of Tuple6, whose elements are correspond to the given slice elements. [[doc](https://github.com/duke-git/lancet/blob/main/docs/tuple.md#Zip6)] + [[play](https://go.dev/play/p/oWPrnUYuFHo)] - **Unzip6** : create a group of slice from a slice of Tuple6. [[doc](https://github.com/duke-git/lancet/blob/main/docs/tuple.md#Unzip6)] + [[play](https://go.dev/play/p/l41XFqCyh5E)] - **Tuple7** : represents a 7 elemnets tuple. [[doc](https://github.com/duke-git/lancet/blob/main/docs/tuple.md#Tuple7)] + [[play](https://go.dev/play/p/dzAgv_Ezub9)] - **Tuple7_Unbox** : returns values in Tuple7. [[doc](https://github.com/duke-git/lancet/blob/main/docs/tuple.md#Tuple7_Unbox)] + [[play](https://go.dev/play/p/R9I8qeDk0zs)] - **Zip7** : create a slice of Tuple7, whose elements are correspond to the given slice elements. [[doc](https://github.com/duke-git/lancet/blob/main/docs/tuple.md#Zip7)] + [[play](https://go.dev/play/p/WUJuo897Egf)] - **Unzip7** : create a group of slice from a slice of Tuple7. [[doc](https://github.com/duke-git/lancet/blob/main/docs/tuple.md#Unzip7)] + [[play](https://go.dev/play/p/hws_P1Fr2j3)] - **Tuple8** : represents a 8 elemnets tuple. [[doc](https://github.com/duke-git/lancet/blob/main/docs/tuple.md#Tuple8)] + [[play](https://go.dev/play/p/YA9S0rz3dRz)] - **Tuple8_Unbox** : returns values in Tuple8. [[doc](https://github.com/duke-git/lancet/blob/main/docs/tuple.md#Tuple8_Unbox)] + [[play](https://go.dev/play/p/PRxLBBb4SMl)] - **Zip8** : create a slice of Tuple8, whose elements are correspond to the given slice elements. [[doc](https://github.com/duke-git/lancet/blob/main/docs/tuple.md#Zip8)] + [[play](https://go.dev/play/p/8V9jWkuJfaQ)] - **Unzip8** : create a group of slice from a slice of Tuple8. [[doc](https://github.com/duke-git/lancet/blob/main/docs/tuple.md#Unzip8)] + [[play](https://go.dev/play/p/1SndOwGsZB4)] - **Tuple9** : represents a 9 elemnets tuple. [[doc](https://github.com/duke-git/lancet/blob/main/docs/tuple.md#Tuple9)] + [[play](https://go.dev/play/p/yS2NGGtZpQr)] - **Tuple9_Unbox** : returns values in Tuple9. [[doc](https://github.com/duke-git/lancet/blob/main/docs/tuple.md#Tuple9_Unbox)] + [[play](https://go.dev/play/p/oFJFGTAuOa8)] - **Zip9** : create a slice of Tuple9, whose elements are correspond to the given slice elements. [[doc](https://github.com/duke-git/lancet/blob/main/docs/tuple.md#Zip9)] + [[play](https://go.dev/play/p/cgsL15QYnfz)] - **Unzip9** : create a group of slice from a slice of Tuple9. [[doc](https://github.com/duke-git/lancet/blob/main/docs/tuple.md#Unzip9)] + [[play](https://go.dev/play/p/91-BU_KURSA)] - **Tuple10** : represents a 10 elemnets tuple. [[doc](https://github.com/duke-git/lancet/blob/main/docs/tuple.md#Tuple10)] + [[play](https://go.dev/play/p/799qqZg0hUv)] - **Tuple10_Unbox** : returns values in Tuple10. [[doc](https://github.com/duke-git/lancet/blob/main/docs/tuple.md#Tuple10_Unbox)] + [[play](https://go.dev/play/p/qfyx3x_X0Cu)] - **Zip10** : create a slice of Tuple10, whose elements are correspond to the given slice elements. [[doc](https://github.com/duke-git/lancet/blob/main/docs/tuple.md#Zip10)] + [[play](https://go.dev/play/p/YSR-2cXnrY4)] - **Unzip10** : create a group of slice from a slice of Tuple10. [[doc](https://github.com/duke-git/lancet/blob/main/docs/tuple.md#Unzip10)] + [[play](https://go.dev/play/p/-taQB6Wfre_z)]

24. Validator package contains some functions for data validation.        index

diff --git a/README_zh-CN.md b/README_zh-CN.md index 489e805..ff3e6fc 100644 --- a/README_zh-CN.md +++ b/README_zh-CN.md @@ -396,6 +396,9 @@ import "github.com/duke-git/lancet/v2/cryptor" - **HmacSha512** : 返回字符串 sha256 hmac 值。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/cryptor_zh-CN.md#HmacSha512)] [[play](https://go.dev/play/p/59Od6m4A0Ud)] +- **Md5Byte** : 返回byte slice的md5值. + [[doc](https://github.com/duke-git/lancet/blob/main/docs/cryptor_zh-CN.md#Md5Byte)] + [[play](https://go.dev/play/p/suraalH8lyC)] - **Md5String** : 返回字符串 md5 值。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/cryptor_zh-CN.md#Md5String)] [[play](https://go.dev/play/p/1bLcVetbTOI)] @@ -485,6 +488,12 @@ import "github.com/duke-git/lancet/v2/datetime" - **GetNowDateTime** : 获取当时日期和时间,返回格式:yyyy-mm-dd hh:mm:ss。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/datetime_zh-CN.md#GetNowDateTime)] [[play](https://go.dev/play/p/pI4AqngD0al)] +- **GetTodayStartTime** : 返回当天开始时间, 格式: yyyy-mm-dd 00:00:00。 + [[doc](https://github.com/duke-git/lancet/blob/main/docs/datetime.md#GetTodayStartTime)] + [[play](https://go.dev/play/p/84siyYF7t99)] +- **GetTodayEndTime** : 返回当天结束时间,格式: yyyy-mm-dd 23:59:59。 + [[doc](https://github.com/duke-git/lancet/blob/main/docs/datetime.md#GetTodayEndTime)] + [[play](https://go.dev/play/p/jjrLnfoqgn3)] - **GetZeroHourTimestamp** : 获取零时时间戳(timestamp of 00:00)。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/datetime_zh-CN.md#GetZeroHourTimestamp)] [[play](https://go.dev/play/p/QmL2oIaGE3q)] @@ -1522,76 +1531,113 @@ import "github.com/duke-git/lancet/v2/tuple" - **Tuple2** : 2 元元组 [[doc](https://github.com/duke-git/lancet/blob/main/docs/tuple_zh-CN.md#Tuple2)] + [[play](https://go.dev/play/p/3sHVqBQpLYN)] - **Tuple2_Unbox** : 返回 2 元元组的字段值。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/tuple_zh-CN.md#Tuple2_Unbox)] + [[play](https://go.dev/play/p/0fD1qfCVwjm)] - **Zip2** : 创建一个 Tuple2 元组切片, 其中元组的元素和传入切片元素相对应。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/tuple_zh-CN.md#Zip2)] + [[play](https://go.dev/play/p/4ncWJJ77Xio)] - **Unzip2** : 根据传入的Tuple2切片,创建一组和Tuple2元素相对应的切片。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/tuple_zh-CN.md#Unzip2)] + [[play](https://go.dev/play/p/KBecr60feXb)] - **Tuple3** : 3 元元组 [[doc](https://github.com/duke-git/lancet/blob/main/docs/tuple_zh-CN.md#Tuple3)] + [[play](https://go.dev/play/p/FtH2sdCLlCf)] - **Tuple3_Unbox** : 返回 3 元元组的字段值。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/tuple_zh-CN.md#Tuple3_Unbox)] + [[play](https://go.dev/play/p/YojLy-id1BS)] - **Zip3** : 创建一个 Tuple3 元组切片, 其中元组的元素和传入切片元素相对应。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/tuple_zh-CN.md#Zip3)] + [[play](https://go.dev/play/p/97NgmsTILfu)] - **Unzip3** : 根据传入的Tuple3切片,创建一组和Tuple3元素相对应的切片。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/tuple_zh-CN.md#Unzip3)] + [[play](https://go.dev/play/p/bba4cpAa7KO)] - **Tuple4** : 4 元元组 [[doc](https://github.com/duke-git/lancet/blob/main/docs/tuple_zh-CN.md#Tuple4)] + [[play](https://go.dev/play/p/D2EqDz096tk)] - **Tuple4_Unbox** : 返回 4 元元组的字段值。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/tuple_zh-CN.md#Tuple4_Unbox)] + [[play](https://go.dev/play/p/ACj9YuACGgW)] - **Zip4** : 创建一个 Tuple4 元组切片, 其中元组的元素和传入切片元素相对应。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/tuple_zh-CN.md#Zip4)] + [[play](https://go.dev/play/p/PEmTYVK5hL4)] - **Unzip4** : 根据传入的Tuple4切片,创建一组和Tuple4元素相对应的切片。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/tuple_zh-CN.md#Unzip4)] + [[play](https://go.dev/play/p/rb8z4gyYSRN)] - **Tuple5** : 5 元元组 [[doc](https://github.com/duke-git/lancet/blob/main/docs/tuple_zh-CN.md#Tuple5)] + [[play](https://go.dev/play/p/2WndmVxPg-r)] - **Tuple5_Unbox** : 返回 5 元元组的字段值。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/tuple_zh-CN.md#Tuple5_Unbox)] + [[play](https://go.dev/play/p/GyIyZHjCvoS)] - **Zip5** : 创建一个 Tuple5 元组切片, 其中元组的元素和传入切片元素相对应。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/tuple_zh-CN.md#Zip5)] + [[play](https://go.dev/play/p/fCAAJLMfBIP)] - **Unzip5** : 根据传入的Tuple5切片,创建一组和Tuple5元素相对应的切片。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/tuple_zh-CN.md#Unzip5)] + [[play](https://go.dev/play/p/gyl6vKfhqPb)] - **Tuple6** : 6 元元组 [[doc](https://github.com/duke-git/lancet/blob/main/docs/tuple_zh-CN.md#Tuple6)] + [[play](https://go.dev/play/p/VjqcCwEJZbs)] - **Tuple6_Unbox** : 返回 6 元元组的字段值。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/tuple_zh-CN.md#Tuple6_Unbox)] + [[play](https://go.dev/play/p/FjIHV7lpxmW)] - **Zip6** : 创建一个 Tuple6 元组切片, 其中元组的元素和传入切片元素相对应。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/tuple_zh-CN.md#Zip6)] + [[play](https://go.dev/play/p/oWPrnUYuFHo)] - **Unzip6** : 根据传入的Tuple6切片,创建一组和Tuple6元素相对应的切片。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/tuple_zh-CN.md#Unzip6)] + [[play](https://go.dev/play/p/l41XFqCyh5E)] - **Tuple7** : 7 元元组 [[doc](https://github.com/duke-git/lancet/blob/main/docs/tuple_zh-CN.md#Tuple7)] + [[play](https://go.dev/play/p/dzAgv_Ezub9)] - **Tuple7_Unbox** : 返回 7 元元组的字段值。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/tuple_zh-CN.md#Tuple7_Unbox)] + [[play](https://go.dev/play/p/R9I8qeDk0zs)] - **Zip7** : 创建一个 Tuple7 元组切片, 其中元组的元素和传入切片元素相对应。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/tuple_zh-CN.md#Zip7)] + [[play](https://go.dev/play/p/WUJuo897Egf)] - **Unzip7** : 根据传入的Tuple7切片,创建一组和Tuple7元素相对应的切片。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/tuple_zh-CN.md#Unzip7)] + [[play](https://go.dev/play/p/hws_P1Fr2j3)] - **Tuple8** : 8 元元组 [[doc](https://github.com/duke-git/lancet/blob/main/docs/tuple_zh-CN.md#Tuple8)] + [[play](https://go.dev/play/p/YA9S0rz3dRz)] - **Tuple8_Unbox** : 返回 8 元元组的字段值。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/tuple_zh-CN.md#Tuple8_Unbox)] + [[play](https://go.dev/play/p/PRxLBBb4SMl)] - **Zip8** : 创建一个 Tuple8 元组切片, 其中元组的元素和传入切片元素相对应。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/tuple_zh-CN.md#Zip8)] + [[play](https://go.dev/play/p/8V9jWkuJfaQ)] - **Unzip8** : 根据传入的Tuple8切片,创建一组和Tuple8元素相对应的切片。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/tuple_zh-CN.md#Unzip8)] + [[play](https://go.dev/play/p/1SndOwGsZB4)] - **Tuple9** : 9 元元组 [[doc](https://github.com/duke-git/lancet/blob/main/docs/tuple_zh-CN.md#Tuple9)] + [[play](https://go.dev/play/p/yS2NGGtZpQr)] - **Tuple9_Unbox** : 返回 9 元元组的字段值。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/tuple_zh-CN.md#Tuple9_Unbox)] + [[play](https://go.dev/play/p/oFJFGTAuOa8)] - **Zip9** : 创建一个 Tuple9 元组切片, 其中元组的元素和传入切片元素相对应。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/tuple_zh-CN.md#Zip9)] + [[play](https://go.dev/play/p/cgsL15QYnfz)] - **Unzip9** : 根据传入的Tuple9切片,创建一组和Tuple9元素相对应的切片。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/tuple_zh-CN.md#Unzip9)] + [[play](https://go.dev/play/p/91-BU_KURSA)] - **Tuple10** : 10 元元组 [[doc](https://github.com/duke-git/lancet/blob/main/docs/tuple_zh-CN.md#Tuple10)] + [[play](https://go.dev/play/p/799qqZg0hUv)] - **Tuple10_Unbox** : 返回 10 元元组的字段值。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/tuple_zh-CN.md#Tuple10_Unbox)] + [[play](https://go.dev/play/p/qfyx3x_X0Cu)] - **Zip10** : 创建一个 Tuple10 元组切片, 其中元组的元素和传入切片元素相对应。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/tuple_zh-CN.md#Zip10)] + [[play](https://go.dev/play/p/YSR-2cXnrY4)] - **Unzip10** : 根据传入的Tuple10切片,创建一组和Tuple10元素相对应的切片。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/tuple_zh-CN.md#Unzip10)] + [[play](https://go.dev/play/p/-taQB6Wfre_z)] +

24. validator 验证器包,包含常用字符串格式验证函数。       回到目录

diff --git a/cryptor/basic.go b/cryptor/basic.go index e190e20..9fa6e78 100644 --- a/cryptor/basic.go +++ b/cryptor/basic.go @@ -40,8 +40,8 @@ func Md5String(s string) string { return hex.EncodeToString(h.Sum(nil)) } -// Md5String return the md5 string of byte slice. -// Play: todo +// Md5Byte return the md5 string of byte slice. +// Play: https://go.dev/play/p/suraalH8lyC func Md5Byte(data []byte) string { h := md5.New() h.Write(data) diff --git a/datetime/datetime.go b/datetime/datetime.go index 9009160..5a23954 100644 --- a/datetime/datetime.go +++ b/datetime/datetime.go @@ -97,13 +97,13 @@ func GetNowDateTime() string { } // GetTodayStartTime return the start time of today, format: yyyy-mm-dd 00:00:00. -// Play: todo +// Play: https://go.dev/play/p/84siyYF7t99 func GetTodayStartTime() string { return time.Now().Format("2006-01-02") + " 00:00:00" } // GetTodayEndTime return the end time of today, format: yyyy-mm-dd 23:59:59. -// Play: todo +// Play: https://go.dev/play/p/jjrLnfoqgn3 func GetTodayEndTime() string { return time.Now().Format("2006-01-02") + " 23:59:59" } diff --git a/docs/datetime_zh-CN.md b/docs/datetime_zh-CN.md index 9f1775e..e2572c6 100644 --- a/docs/datetime_zh-CN.md +++ b/docs/datetime_zh-CN.md @@ -717,7 +717,7 @@ func main() { ### GetTodayStartTime -

返回当天开始时间, 格式: yyyy-mm-dd 00:00:00.

+

返回当天开始时间, 格式: yyyy-mm-dd 00:00:00。

函数签名: @@ -746,7 +746,7 @@ func main() { ### GetTodayEndTime -

返回当天结束时间,格式: yyyy-mm-dd 23:59:59.

+

返回当天结束时间,格式: yyyy-mm-dd 23:59:59。

函数签名: diff --git a/docs/tuple.md b/docs/tuple.md index dbf6379..182f109 100644 --- a/docs/tuple.md +++ b/docs/tuple.md @@ -237,9 +237,9 @@ import ( ) func main() { - t := tuple.NewTuple2(1, 0.1, "a") + t := tuple.NewTuple3(1, 0.1, "a") v1, v2, v3 := t.Unbox() - fmt.Printf("%v %v %v", t.FieldA, t.FieldB, t.FieldC) + fmt.Printf("%v %v %v", v1, v2, v3) // Output: 1 0.1 a } @@ -1134,8 +1134,6 @@ func main() { fmt.Printf("%v %v %v %v %v %v %v %v %v %v", v1, v2, v3, v4, v5, v6, v7, v8, v9, v10) // Output: 1 0.1 a true 2 2.2 b c map[a:1] {a} - - // Output: 1 0.1 a true 2 2.2 b c map[a:1] } ``` diff --git a/docs/tuple_zh-CN.md b/docs/tuple_zh-CN.md index d8671b9..85266fc 100644 --- a/docs/tuple_zh-CN.md +++ b/docs/tuple_zh-CN.md @@ -239,7 +239,7 @@ import ( func main() { t := tuple.NewTuple2(1, 0.1, "a") v1, v2, v3 := t.Unbox() - fmt.Printf("%v %v %v", t.FieldA, t.FieldB, t.FieldC) + fmt.Printf("%v %v %v", v1, v2, v3) // Output: 1 0.1 a } @@ -1134,8 +1134,6 @@ func main() { fmt.Printf("%v %v %v %v %v %v %v %v %v %v", v1, v2, v3, v4, v5, v6, v7, v8, v9, v10) // Output: 1 0.1 a true 2 2.2 b c map[a:1] {a} - - // Output: 1 0.1 a true 2 2.2 b c map[a:1] } ``` diff --git a/tuple/tuple.go b/tuple/tuple.go index 13bd5f4..4554e26 100644 --- a/tuple/tuple.go +++ b/tuple/tuple.go @@ -13,19 +13,19 @@ type Tuple2[A any, B any] struct { } // Unbox returns values in tuple. -// Play: todo +// Play: https://go.dev/play/p/0fD1qfCVwjm func (t Tuple2[A, B]) Unbox() (A, B) { return t.FieldA, t.FieldB } // NewTuple2 creates a 2 elemnets tuple from a list of values. -// Play: todo +// Play: https://go.dev/play/p/3sHVqBQpLYN func NewTuple2[A any, B any](a A, b B) Tuple2[A, B] { return Tuple2[A, B]{FieldA: a, FieldB: b} } // Zip2 create a slice of Tuple2, whose elements are correspond to the given slice elements. -// Play: todo +// Play: https://go.dev/play/p/4ncWJJ77Xio func Zip2[A any, B any](a []A, b []B) []Tuple2[A, B] { size := mathutil.Max(len(a), len(b)) @@ -42,7 +42,7 @@ func Zip2[A any, B any](a []A, b []B) []Tuple2[A, B] { } // Unzip2 creates a group of slice from a slice of Tuple2. -// Play: todo +// Play: https://go.dev/play/p/KBecr60feXb func Unzip2[A any, B any](tuples []Tuple2[A, B]) ([]A, []B) { size := len(tuples) @@ -65,19 +65,19 @@ type Tuple3[A any, B any, C any] struct { } // Unbox returns values in tuple. -// Play: todo +// Play: https://go.dev/play/p/YojLy-id1BS func (t Tuple3[A, B, C]) Unbox() (A, B, C) { return t.FieldA, t.FieldB, t.FieldC } // NewTuple3 creates a 3 elemnets tuple from a list of values. -// Play: todo +// Play: https://go.dev/play/p/FtH2sdCLlCf func NewTuple3[A any, B any, C any](a A, b B, c C) Tuple3[A, B, C] { return Tuple3[A, B, C]{FieldA: a, FieldB: b, FieldC: c} } // Zip3 create a slice of Tuple3, whose elements are correspond to the given slice elements. -// Play: todo +// Play: https://go.dev/play/p/97NgmsTILfu func Zip3[A any, B any, C any](a []A, b []B, c []C) []Tuple3[A, B, C] { size := mathutil.Max(len(a), len(b), len(c)) @@ -95,7 +95,7 @@ func Zip3[A any, B any, C any](a []A, b []B, c []C) []Tuple3[A, B, C] { } // Unzip3 creates a group of slice from a slice of Tuple3. -// Play: todo +// Play: https://go.dev/play/p/bba4cpAa7KO func Unzip3[A any, B any, C any](tuples []Tuple3[A, B, C]) ([]A, []B, []C) { size := len(tuples) @@ -121,19 +121,19 @@ type Tuple4[A any, B any, C any, D any] struct { } // Unbox returns values in tuple. -// Play: todo +// Play: https://go.dev/play/p/ACj9YuACGgW func (t Tuple4[A, B, C, D]) Unbox() (A, B, C, D) { return t.FieldA, t.FieldB, t.FieldC, t.FieldD } // NewTuple4 creates a 4 elemnets tuple from a list of values. -// Play: todo +// Play: https://go.dev/play/p/D2EqDz096tk func NewTuple4[A any, B any, C any, D any](a A, b B, c C, d D) Tuple4[A, B, C, D] { return Tuple4[A, B, C, D]{FieldA: a, FieldB: b, FieldC: c, FieldD: d} } // Zip4 create a slice of Tuple4, whose elements are correspond to the given slice elements. -// Play: todo +// Play: https://go.dev/play/p/PEmTYVK5hL4 func Zip4[A any, B any, C any, D any](a []A, b []B, c []C, d []D) []Tuple4[A, B, C, D] { size := mathutil.Max(len(a), len(b), len(c), len(d)) @@ -152,7 +152,7 @@ func Zip4[A any, B any, C any, D any](a []A, b []B, c []C, d []D) []Tuple4[A, B, } // Unzip4 creates a group of slice from a slice of Tuple4. -// Play: todo +// Play: https://go.dev/play/p/rb8z4gyYSRN func Unzip4[A any, B any, C any, D any](tuples []Tuple4[A, B, C, D]) ([]A, []B, []C, []D) { size := len(tuples) @@ -181,19 +181,19 @@ type Tuple5[A any, B any, C any, D any, E any] struct { } // Unbox returns values in tuple. -// Play: todo +// Play: https://go.dev/play/p/GyIyZHjCvoS func (t Tuple5[A, B, C, D, E]) Unbox() (A, B, C, D, E) { return t.FieldA, t.FieldB, t.FieldC, t.FieldD, t.FieldE } // NewTuple5 creates a 5 elemnets tuple from a list of values. -// Play: todo +// Play: https://go.dev/play/p/2WndmVxPg-r func NewTuple5[A any, B any, C any, D any, E any](a A, b B, c C, d D, e E) Tuple5[A, B, C, D, E] { return Tuple5[A, B, C, D, E]{FieldA: a, FieldB: b, FieldC: c, FieldD: d, FieldE: e} } // Zip5 create a slice of Tuple5, whose elements are correspond to the given slice elements. -// Play: todo +// Play: https://go.dev/play/p/fCAAJLMfBIP func Zip5[A any, B any, C any, D any, E any](a []A, b []B, c []C, d []D, e []E) []Tuple5[A, B, C, D, E] { size := mathutil.Max(len(a), len(b), len(c), len(d), len(e)) @@ -215,7 +215,7 @@ func Zip5[A any, B any, C any, D any, E any](a []A, b []B, c []C, d []D, e []E) } // Unzip5 creates a group of slice from a slice of Tuple5. -// Play: todo +// Play: https://go.dev/play/p/gyl6vKfhqPb func Unzip5[A any, B any, C any, D any, E any](tuples []Tuple5[A, B, C, D, E]) ([]A, []B, []C, []D, []E) { size := len(tuples) @@ -247,19 +247,19 @@ type Tuple6[A any, B any, C any, D any, E any, F any] struct { } // Unbox returns values in tuple. -// Play: todo +// Play: https://go.dev/play/p/FjIHV7lpxmW func (t Tuple6[A, B, C, D, E, F]) Unbox() (A, B, C, D, E, F) { return t.FieldA, t.FieldB, t.FieldC, t.FieldD, t.FieldE, t.FieldF } // NewTuple6 creates a 6 elemnets tuple from a list of values. -// Play: todo +// Play: https://go.dev/play/p/VjqcCwEJZbs func NewTuple6[A any, B any, C any, D any, E any, F any](a A, b B, c C, d D, e E, f F) Tuple6[A, B, C, D, E, F] { return Tuple6[A, B, C, D, E, F]{FieldA: a, FieldB: b, FieldC: c, FieldD: d, FieldE: e, FieldF: f} } // Zip6 create a slice of Tuple6, whose elements are correspond to the given slice elements. -// Play: todo +// Play: https://go.dev/play/p/oWPrnUYuFHo func Zip6[A any, B any, C any, D any, E any, F any](a []A, b []B, c []C, d []D, e []E, f []F) []Tuple6[A, B, C, D, E, F] { size := mathutil.Max(len(a), len(b), len(c), len(d), len(e), len(f)) @@ -282,7 +282,7 @@ func Zip6[A any, B any, C any, D any, E any, F any](a []A, b []B, c []C, d []D, } // Unzip6 creates a group of slice from a slice of Tuple6. -// Play: todo +// Play: https://go.dev/play/p/l41XFqCyh5E func Unzip6[A any, B any, C any, D any, E any, F any](tuples []Tuple6[A, B, C, D, E, F]) ([]A, []B, []C, []D, []E, []F) { size := len(tuples) @@ -317,19 +317,19 @@ type Tuple7[A any, B any, C any, D any, E any, F any, G any] struct { } // Unbox returns values in tuple. -// Play: todo +// Play: https://go.dev/play/p/R9I8qeDk0zs func (t Tuple7[A, B, C, D, E, F, G]) Unbox() (A, B, C, D, E, F, G) { return t.FieldA, t.FieldB, t.FieldC, t.FieldD, t.FieldE, t.FieldF, t.FieldG } // NewTuple7 creates a 7 elemnets tuple from a list of values. -// Play: todo +// Play: https://go.dev/play/p/dzAgv_Ezub9 func NewTuple7[A any, B any, C any, D any, E any, F any, G any](a A, b B, c C, d D, e E, f F, g G) Tuple7[A, B, C, D, E, F, G] { return Tuple7[A, B, C, D, E, F, G]{FieldA: a, FieldB: b, FieldC: c, FieldD: d, FieldE: e, FieldF: f, FieldG: g} } // Zip7 create a slice of Tuple7, whose elements are correspond to the given slice elements. -// Play: todo +// Play: https://go.dev/play/p/WUJuo897Egf func Zip7[A any, B any, C any, D any, E any, F any, G any](a []A, b []B, c []C, d []D, e []E, f []F, g []G) []Tuple7[A, B, C, D, E, F, G] { size := mathutil.Max(len(a), len(b), len(c), len(d), len(e), len(f), len(g)) @@ -354,7 +354,7 @@ func Zip7[A any, B any, C any, D any, E any, F any, G any](a []A, b []B, c []C, } // Unzip7 creates a group of slice from a slice of Tuple7. -// Play: todo +// Play: https://go.dev/play/p/hws_P1Fr2j3 func Unzip7[A any, B any, C any, D any, E any, F any, G any](tuples []Tuple7[A, B, C, D, E, F, G]) ([]A, []B, []C, []D, []E, []F, []G) { size := len(tuples) @@ -392,19 +392,19 @@ type Tuple8[A any, B any, C any, D any, E any, F any, G any, H any] struct { } // Unbox returns values in tuple. -// Play: todo +// Play: https://go.dev/play/p/PRxLBBb4SMl func (t Tuple8[A, B, C, D, E, F, G, H]) Unbox() (A, B, C, D, E, F, G, H) { return t.FieldA, t.FieldB, t.FieldC, t.FieldD, t.FieldE, t.FieldF, t.FieldG, t.FieldH } // NewTuple8 creates a 8 elemnets tuple from a list of values. -// Play: todo +// Play: https://go.dev/play/p/YA9S0rz3dRz func NewTuple8[A any, B any, C any, D any, E any, F any, G any, H any](a A, b B, c C, d D, e E, f F, g G, h H) Tuple8[A, B, C, D, E, F, G, H] { return Tuple8[A, B, C, D, E, F, G, H]{FieldA: a, FieldB: b, FieldC: c, FieldD: d, FieldE: e, FieldF: f, FieldG: g, FieldH: h} } // Zip8 create a slice of Tuple8, whose elements are correspond to the given slice elements. -// Play: todo +// Play: https://go.dev/play/p/8V9jWkuJfaQ func Zip8[A any, B any, C any, D any, E any, F any, G any, H any](a []A, b []B, c []C, d []D, e []E, f []F, g []G, h []H) []Tuple8[A, B, C, D, E, F, G, H] { size := mathutil.Max(len(a), len(b), len(c), len(d), len(e), len(f), len(g), len(h)) @@ -430,7 +430,7 @@ func Zip8[A any, B any, C any, D any, E any, F any, G any, H any](a []A, b []B, } // Unzip8 creates a group of slice from a slice of Tuple8. -// Play: todo +// Play: https://go.dev/play/p/1SndOwGsZB4 func Unzip8[A any, B any, C any, D any, E any, F any, G any, H any](tuples []Tuple8[A, B, C, D, E, F, G, H]) ([]A, []B, []C, []D, []E, []F, []G, []H) { size := len(tuples) @@ -471,19 +471,19 @@ type Tuple9[A any, B any, C any, D any, E any, F any, G any, H any, I any] struc } // Unbox returns values in tuple. -// Play: todo +// Play: https://go.dev/play/p/oFJFGTAuOa8 func (t Tuple9[A, B, C, D, E, F, G, H, I]) Unbox() (A, B, C, D, E, F, G, H, I) { return t.FieldA, t.FieldB, t.FieldC, t.FieldD, t.FieldE, t.FieldF, t.FieldG, t.FieldH, t.FieldI } // NewTuple9 creates a 9 elemnets tuple from a list of values. -// Play: todo +// Play: https://go.dev/play/p/yS2NGGtZpQr func NewTuple9[A any, B any, C any, D any, E any, F any, G any, H any, I any](a A, b B, c C, d D, e E, f F, g G, h H, i I) Tuple9[A, B, C, D, E, F, G, H, I] { return Tuple9[A, B, C, D, E, F, G, H, I]{FieldA: a, FieldB: b, FieldC: c, FieldD: d, FieldE: e, FieldF: f, FieldG: g, FieldH: h, FieldI: i} } // Zip9 create a slice of Tuple9, whose elements are correspond to the given slice elements. -// Play: todo +// Play: https://go.dev/play/p/cgsL15QYnfz func Zip9[A any, B any, C any, D any, E any, F any, G any, H any, I any](a []A, b []B, c []C, d []D, e []E, f []F, g []G, h []H, i []I) []Tuple9[A, B, C, D, E, F, G, H, I] { size := mathutil.Max(len(a), len(b), len(c), len(d), len(e), len(f), len(g), len(h), len(i)) @@ -510,7 +510,7 @@ func Zip9[A any, B any, C any, D any, E any, F any, G any, H any, I any](a []A, } // Unzip9 creates a group of slice from a slice of Tuple9. -// Play: todo +// Play: https://go.dev/play/p/91-BU_KURSA func Unzip9[A any, B any, C any, D any, E any, F any, G any, H any, I any](tuples []Tuple9[A, B, C, D, E, F, G, H, I]) ([]A, []B, []C, []D, []E, []F, []G, []H, []I) { size := len(tuples) @@ -554,19 +554,19 @@ type Tuple10[A any, B any, C any, D any, E any, F any, G any, H any, I any, J an } // Unbox returns values in tuple. -// Play: todo +// Play: https://go.dev/play/p/qfyx3x_X0Cu func (t Tuple10[A, B, C, D, E, F, G, H, I, J]) Unbox() (A, B, C, D, E, F, G, H, I, J) { return t.FieldA, t.FieldB, t.FieldC, t.FieldD, t.FieldE, t.FieldF, t.FieldG, t.FieldH, t.FieldI, t.FieldJ } // NewTuple10 creates a 10 elemnets tuple from a list of values. -// Play: todo +// Play: https://go.dev/play/p/799qqZg0hUv func NewTuple10[A any, B any, C any, D any, E any, F any, G any, H any, I any, J any](a A, b B, c C, d D, e E, f F, g G, h H, i I, j J) Tuple10[A, B, C, D, E, F, G, H, I, J] { return Tuple10[A, B, C, D, E, F, G, H, I, J]{FieldA: a, FieldB: b, FieldC: c, FieldD: d, FieldE: e, FieldF: f, FieldG: g, FieldH: h, FieldI: i, FieldJ: j} } // Zip10 create a slice of Tuple10, whose elements are correspond to the given slice elements. -// Play: todo +// Play: https://go.dev/play/p/YSR-2cXnrY4 func Zip10[A any, B any, C any, D any, E any, F any, G any, H any, I any, J any](a []A, b []B, c []C, d []D, e []E, f []F, g []G, h []H, i []I, j []J) []Tuple10[A, B, C, D, E, F, G, H, I, J] { size := mathutil.Max(len(a), len(b), len(c), len(d), len(e), len(f), len(g), len(h), len(i), len(j)) @@ -595,7 +595,7 @@ func Zip10[A any, B any, C any, D any, E any, F any, G any, H any, I any, J any] } // Unzip10 creates a group of slice from a slice of Tuple10. -// Play: todo +// Play: https://go.dev/play/p/-taQB6Wfre_z func Unzip10[A any, B any, C any, D any, E any, F any, G any, H any, I any, J any](tuples []Tuple10[A, B, C, D, E, F, G, H, I, J]) ([]A, []B, []C, []D, []E, []F, []G, []H, []I, []J) { size := len(tuples)