1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-23 13:52:26 +08:00

Compare commits

...

6 Commits

Author SHA1 Message Date
dudaodong
0d0848ac67 refactor: use for loop than for range 2023-07-10 10:56:53 +08:00
dudaodong
d5334f892f feat: add Join 2023-07-10 10:51:43 +08:00
dudaodong
36ef5b3bd3 doc: add doc for HasKey 2023-07-10 10:39:55 +08:00
dudaodong
6f48b00c88 feat: add HasKey 2023-07-10 10:33:04 +08:00
dudaodong
7b744c299e fix: fix bug of CreateDir 2023-07-10 10:13:23 +08:00
dudaodong
154ec56780 doc: add go playground demo 2023-07-04 16:31:13 +08:00
23 changed files with 414 additions and 68 deletions

View File

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

View File

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

View File

@@ -40,8 +40,8 @@ func Md5String(s string) string {
return hex.EncodeToString(h.Sum(nil)) return hex.EncodeToString(h.Sum(nil))
} }
// Md5String return the md5 string of byte slice. // Md5Byte return the md5 string of byte slice.
// Play: todo // Play: https://go.dev/play/p/suraalH8lyC
func Md5Byte(data []byte) string { func Md5Byte(data []byte) string {
h := md5.New() h := md5.New()
h.Write(data) h.Write(data)

View File

@@ -97,13 +97,13 @@ func GetNowDateTime() string {
} }
// GetTodayStartTime return the start time of today, format: yyyy-mm-dd 00:00:00. // 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 { func GetTodayStartTime() string {
return time.Now().Format("2006-01-02") + " 00:00:00" return time.Now().Format("2006-01-02") + " 00:00:00"
} }
// GetTodayEndTime return the end time of today, format: yyyy-mm-dd 23:59:59. // 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 { func GetTodayEndTime() string {
return time.Now().Format("2006-01-02") + " 23:59:59" return time.Now().Format("2006-01-02") + " 23:59:59"
} }

View File

@@ -717,7 +717,7 @@ func main() {
### <span id="GetTodayStartTime">GetTodayStartTime</span> ### <span id="GetTodayStartTime">GetTodayStartTime</span>
<p>返回当天开始时间, 格式: yyyy-mm-dd 00:00:00.</p> <p>返回当天开始时间, 格式: yyyy-mm-dd 00:00:00</p>
<b>函数签名:</b> <b>函数签名:</b>
@@ -746,7 +746,7 @@ func main() {
### <span id="GetTodayEndTime">GetTodayEndTime</span> ### <span id="GetTodayEndTime">GetTodayEndTime</span>
<p>返回当天结束时间,格式: yyyy-mm-dd 23:59:59.</p> <p>返回当天结束时间,格式: yyyy-mm-dd 23:59:59</p>
<b>函数签名:</b> <b>函数签名:</b>

View File

@@ -108,7 +108,7 @@ func main() {
### <span id="CreateDir">CreateDir</span> ### <span id="CreateDir">CreateDir</span>
<p>Create directory in absolute path. param `absPath` like /a/, /a/b/.</p> <p>Create directory in absolute path. param `absPath` like /a, /a/b.</p>
<b>Signature:</b> <b>Signature:</b>
@@ -127,7 +127,7 @@ import (
) )
func main() { func main() {
err := fileutil.CreateDir("/a/") err := fileutil.CreateDir("/a/b") // will create folder /a/b
fmt.Println(err) fmt.Println(err)
} }
``` ```

View File

@@ -108,7 +108,7 @@ func main() {
### <span id="CreateDir">CreateDir</span> ### <span id="CreateDir">CreateDir</span>
<p>使用绝对路径创建嵌套目录,例如/a/, /a/b/</p> <p>使用绝对路径创建嵌套目录,例如/a/, /a/b</p>
<b>函数签名:</b> <b>函数签名:</b>
@@ -127,7 +127,7 @@ import (
) )
func main() { func main() {
err := fileutil.CreateDir("/a/") err := fileutil.CreateDir("/a/b") // will create folder /a/b
fmt.Println(err) fmt.Println(err)
} }
``` ```

View File

@@ -43,6 +43,7 @@ import (
- [Merge](#Merge) - [Merge](#Merge)
- [Minus](#Minus) - [Minus](#Minus)
- [IsDisjoint](#IsDisjoint) - [IsDisjoint](#IsDisjoint)
- [HasKey](#HasKey)
<div STYLE="page-break-after: always;"></div> <div STYLE="page-break-after: always;"></div>
@@ -893,7 +894,7 @@ func main() {
### <span id="IsDisjoint">IsDisjoint</span> ### <span id="IsDisjoint">IsDisjoint</span>
<p>Checks two maps are disjoint if they have no keys in common</p> <p>Checks two maps are disjoint if they have no keys in common.</p>
<b>Signature:</b> <b>Signature:</b>
@@ -937,3 +938,49 @@ func main() {
// false // false
} }
``` ```
### <span id="HasKey">HasKey</span>
<p>Checks if map has key or not. This function is used to replace the following boilerplate code:</p>
```go
_, haskey := amap["baz"];
if haskey {
fmt.Println("map has key baz")
}
```
<b>Signature:</b>
```go
func HasKey[K comparable, V any](m map[K]V, key K) bool
```
<b>Example:</b>
```go
package main
import (
"fmt"
"github.com/duke-git/lancet/v2/maputil"
)
func main() {
m := map[string]int{
"a": 1,
"b": 2,
}
result1 := HasKey(m, "a")
result2 := HasKey(m, "c")
fmt.Println(result1)
fmt.Println(result2)
// Output:
// true
// false
}
```

View File

@@ -43,6 +43,7 @@ import (
- [Merge](#Merge) - [Merge](#Merge)
- [Minus](#Minus) - [Minus](#Minus)
- [IsDisjoint](#IsDisjoint) - [IsDisjoint](#IsDisjoint)
- [HasKey](#HasKey)
<div STYLE="page-break-after: always;"></div> <div STYLE="page-break-after: always;"></div>
@@ -932,3 +933,49 @@ func main() {
// false // false
} }
``` ```
### <span id="HasKey">HasKey</span>
<p>检查map是否包含某个key。用于代替以下样板代码:</p>
```go
_, haskey := amap["baz"];
if haskey {
fmt.Println("map has key baz")
}
```
<b>函数签名:</b>
```go
func HasKey[K comparable, V any](m map[K]V, key K) bool
```
<b>示例:</b>
```go
package main
import (
"fmt"
"github.com/duke-git/lancet/v2/maputil"
)
func main() {
m := map[string]int{
"a": 1,
"b": 2,
}
result1 := HasKey(m, "a")
result2 := HasKey(m, "c")
fmt.Println(result1)
fmt.Println(result2)
// Output:
// true
// false
}
```

View File

@@ -90,6 +90,7 @@ import (
- [UpdateAt](#UpdateAt) - [UpdateAt](#UpdateAt)
- [Without](#Without) - [Without](#Without)
- [KeyBy](#KeyBy) - [KeyBy](#KeyBy)
- [Join](#Join)
<div STYLE="page-break-after: always;"></div> <div STYLE="page-break-after: always;"></div>
@@ -2417,3 +2418,36 @@ func main() {
// map[1:a 2:ab 3:abc] // map[1:a 2:ab 3:abc]
} }
``` ```
### <span id="Join">Join</span>
<p>Join the slice item with specify separator.</p>
<b>Signature:</b>
```go
func Join[T any](s []T, separator string) string
```
<b>Example:</b>
```go
import (
"fmt"
"github.com/duke-git/lancet/v2/slice"
)
func main() {
nums := []int{1, 2, 3, 4, 5}
result1 := slice.Join(nums, ",")
result2 := slice.Join(nums, "-")
fmt.Println(result1)
fmt.Println(result2)
// Output:
// 1,2,3,4,5
// 1-2-3-4-5
}
```

View File

@@ -90,6 +90,7 @@ import (
- [UpdateAt](#UpdateAt) - [UpdateAt](#UpdateAt)
- [Without](#Without) - [Without](#Without)
- [KeyBy](#KeyBy) - [KeyBy](#KeyBy)
- [Join](#Join)
<div STYLE="page-break-after: always;"></div> <div STYLE="page-break-after: always;"></div>
@@ -2390,7 +2391,7 @@ func main() {
### <span id="KeyBy">KeyBy</span> ### <span id="KeyBy">KeyBy</span>
<p>将切片每个元素调用函数后转为map</p> <p>将切片每个元素调用函数后转为map</p>
<b>函数签名:</b> <b>函数签名:</b>
@@ -2417,3 +2418,36 @@ func main() {
// map[1:a 2:ab 3:abc] // map[1:a 2:ab 3:abc]
} }
``` ```
### <span id="Join">Join</span>
<p>用指定的分隔符链接切片元素。</p>
<b>函数签名:</b>
```go
func Join[T any](s []T, separator string) string
```
<b>示例:</b>
```go
import (
"fmt"
"github.com/duke-git/lancet/v2/slice"
)
func main() {
nums := []int{1, 2, 3, 4, 5}
result1 := slice.Join(nums, ",")
result2 := slice.Join(nums, "-")
fmt.Println(result1)
fmt.Println(result2)
// Output:
// 1,2,3,4,5
// 1-2-3-4-5
}
```

View File

@@ -237,9 +237,9 @@ import (
) )
func main() { func main() {
t := tuple.NewTuple2(1, 0.1, "a") t := tuple.NewTuple3(1, 0.1, "a")
v1, v2, v3 := t.Unbox() 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 // 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) 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] {a}
// Output: 1 0.1 a true 2 2.2 b c map[a:1]
} }
``` ```

View File

@@ -239,7 +239,7 @@ import (
func main() { func main() {
t := tuple.NewTuple2(1, 0.1, "a") t := tuple.NewTuple2(1, 0.1, "a")
v1, v2, v3 := t.Unbox() 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 // 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) 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] {a}
// Output: 1 0.1 a true 2 2.2 b c map[a:1]
} }
``` ```

View File

@@ -52,7 +52,8 @@ func CreateFile(path string) bool {
// CreateDir create directory in absolute path. param `absPath` like /a/, /a/b/. // CreateDir create directory in absolute path. param `absPath` like /a/, /a/b/.
// Play: https://go.dev/play/p/qUuCe1OGQnM // Play: https://go.dev/play/p/qUuCe1OGQnM
func CreateDir(absPath string) error { func CreateDir(absPath string) error {
return os.MkdirAll(path.Dir(absPath), os.ModePerm) // return os.MkdirAll(path.Dir(absPath), os.ModePerm)
return os.MkdirAll(absPath, os.ModePerm)
} }
// IsDir checks if the path is directory or not. // IsDir checks if the path is directory or not.

View File

@@ -39,7 +39,7 @@ func ExampleCreateFile() {
func ExampleCreateDir() { func ExampleCreateDir() {
pwd, _ := os.Getwd() pwd, _ := os.Getwd()
dirPath := pwd + "/test_xxx/" dirPath := pwd + "/createdir/a/b"
result1 := IsExist(dirPath) result1 := IsExist(dirPath)
@@ -48,16 +48,22 @@ func ExampleCreateDir() {
return return
} }
result2 := IsExist(dirPath) result2 := IsExist(pwd + "/createdir/")
result3 := IsExist(pwd + "/createdir/a")
os.Remove(dirPath) result4 := IsExist(pwd + "/createdir/a/b")
fmt.Println(result1) fmt.Println(result1)
fmt.Println(result2) fmt.Println(result2)
fmt.Println(result3)
fmt.Println(result4)
os.RemoveAll(pwd + "/createdir/")
// Output: // Output:
// false // false
// true // true
// true
// true
} }
func ExampleIsDir() { func ExampleIsDir() {

View File

@@ -50,7 +50,7 @@ func TestCreateDir(t *testing.T) {
t.FailNow() t.FailNow()
} }
dirPath := pwd + "/a/" dirPath := pwd + "/a/b"
err = CreateDir(dirPath) err = CreateDir(dirPath)
if err != nil { if err != nil {
t.Error(err) t.Error(err)
@@ -58,7 +58,9 @@ func TestCreateDir(t *testing.T) {
} }
assert.Equal(true, IsExist(dirPath)) assert.Equal(true, IsExist(dirPath))
os.Remove(dirPath)
os.RemoveAll(pwd + "/a")
assert.Equal(false, IsExist(dirPath)) assert.Equal(false, IsExist(dirPath))
} }

View File

@@ -289,3 +289,21 @@ func MapValues[K comparable, V any, T any](m map[K]V, iteratee func(key K, value
return result return result
} }
// HasKey checks if map has key or not.
// This function is used to replace the following boilerplate code:
// _, haskey := amap["baz"];
//
// if haskey {
// fmt.Println("map has key baz")
// }
//
// Play: todo
func HasKey[K comparable, V any](m map[K]V, key K) bool {
_, haskey := m[key]
if haskey {
return true
}
return false
}

View File

@@ -433,3 +433,20 @@ func ExampleMapTo() {
// <nil> // <nil>
// {Nothin 28 123456789 {test 1}} // {Nothin 28 123456789 {test 1}}
} }
func ExampleHasKey() {
m := map[string]int{
"a": 1,
"b": 2,
}
result1 := HasKey(m, "a")
result2 := HasKey(m, "c")
fmt.Println(result1)
fmt.Println(result2)
// Output:
// true
// false
}

View File

@@ -458,3 +458,17 @@ func TestMapValues(t *testing.T) {
assert.Equal(expected, result) assert.Equal(expected, result)
} }
func TestHasKey(t *testing.T) {
t.Parallel()
assert := internal.NewAssert(t, "TestHasKey")
m := map[string]int{
"a": 1,
"b": 2,
}
assert.Equal(true, HasKey(m, "a"))
assert.Equal(false, HasKey(m, "c"))
}

View File

@@ -9,6 +9,7 @@ import (
"math/rand" "math/rand"
"reflect" "reflect"
"sort" "sort"
"strings"
"time" "time"
"golang.org/x/exp/constraints" "golang.org/x/exp/constraints"
@@ -436,8 +437,8 @@ func flattenRecursive(value reflect.Value, result reflect.Value) reflect.Value {
// ForEach iterates over elements of slice and invokes function for each element. // ForEach iterates over elements of slice and invokes function for each element.
// Play: https://go.dev/play/p/DrPaa4YsHRF // Play: https://go.dev/play/p/DrPaa4YsHRF
func ForEach[T any](slice []T, iteratee func(index int, item T)) { func ForEach[T any](slice []T, iteratee func(index int, item T)) {
for i, v := range slice { for i := 0; i < len(slice); i++ {
iteratee(i, v) iteratee(i, slice[i])
} }
} }
@@ -445,8 +446,8 @@ func ForEach[T any](slice []T, iteratee func(index int, item T)) {
// when iteratee return false, will break the for each loop. // when iteratee return false, will break the for each loop.
// Play: https://go.dev/play/p/qScs39f3D9W // Play: https://go.dev/play/p/qScs39f3D9W
func ForEachWithBreak[T any](slice []T, iteratee func(index int, item T) bool) { func ForEachWithBreak[T any](slice []T, iteratee func(index int, item T) bool) {
for i, v := range slice { for i := 0; i < len(slice); i++ {
if !iteratee(i, v) { if !iteratee(i, slice[i]) {
break break
} }
} }
@@ -457,8 +458,8 @@ func ForEachWithBreak[T any](slice []T, iteratee func(index int, item T) bool) {
func Map[T any, U any](slice []T, iteratee func(index int, item T) U) []U { func Map[T any, U any](slice []T, iteratee func(index int, item T) U) []U {
result := make([]U, len(slice), cap(slice)) result := make([]U, len(slice), cap(slice))
for i, v := range slice { for i := 0; i < len(slice); i++ {
result[i] = iteratee(i, v) result[i] = iteratee(i, slice[i])
} }
return result return result
@@ -1188,3 +1189,13 @@ func KeyBy[T any, U comparable](slice []T, iteratee func(item T) U) map[U]T {
return result return result
} }
// Join the slice item with specify separator.
// Play: todo
func Join[T any](s []T, separator string) string {
str := Map(s, func(_ int, item T) string {
return fmt.Sprint(item)
})
return strings.Join(str, separator)
}

View File

@@ -1032,3 +1032,17 @@ func ExampleKeyBy() {
// Output: // Output:
// map[1:a 2:ab 3:abc] // map[1:a 2:ab 3:abc]
} }
func ExampleJoin() {
nums := []int{1, 2, 3, 4, 5}
result1 := Join(nums, ",")
result2 := Join(nums, "-")
fmt.Println(result1)
fmt.Println(result2)
// Output:
// 1,2,3,4,5
// 1-2-3-4-5
}

View File

@@ -1161,3 +1161,17 @@ func TestRepeat(t *testing.T) {
assert.Equal([]string{}, Repeat("a", 0)) assert.Equal([]string{}, Repeat("a", 0))
assert.Equal([]string{"a", "a", "a", "a", "a", "a"}, Repeat("a", 6)) assert.Equal([]string{"a", "a", "a", "a", "a", "a"}, Repeat("a", 6))
} }
func TestJoin(t *testing.T) {
t.Parallel()
assert := internal.NewAssert(t, "TestJoin")
nums := []int{1, 2, 3, 4, 5}
result1 := Join(nums, ",")
result2 := Join(nums, "-")
assert.Equal("1,2,3,4,5", result1)
assert.Equal("1-2-3-4-5", result2)
}

View File

@@ -13,19 +13,19 @@ type Tuple2[A any, B any] struct {
} }
// Unbox returns values in tuple. // Unbox returns values in tuple.
// Play: todo // Play: https://go.dev/play/p/0fD1qfCVwjm
func (t Tuple2[A, B]) Unbox() (A, B) { func (t Tuple2[A, B]) Unbox() (A, B) {
return t.FieldA, t.FieldB return t.FieldA, t.FieldB
} }
// NewTuple2 creates a 2 elemnets tuple from a list of values. // 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] { func NewTuple2[A any, B any](a A, b B) Tuple2[A, B] {
return Tuple2[A, B]{FieldA: a, FieldB: b} return Tuple2[A, B]{FieldA: a, FieldB: b}
} }
// Zip2 create a slice of Tuple2, whose elements are correspond to the given slice elements. // 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] { func Zip2[A any, B any](a []A, b []B) []Tuple2[A, B] {
size := mathutil.Max(len(a), len(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. // 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) { func Unzip2[A any, B any](tuples []Tuple2[A, B]) ([]A, []B) {
size := len(tuples) size := len(tuples)
@@ -65,19 +65,19 @@ type Tuple3[A any, B any, C any] struct {
} }
// Unbox returns values in tuple. // 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) { func (t Tuple3[A, B, C]) Unbox() (A, B, C) {
return t.FieldA, t.FieldB, t.FieldC return t.FieldA, t.FieldB, t.FieldC
} }
// NewTuple3 creates a 3 elemnets tuple from a list of values. // 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] { 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} 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. // 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] { 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)) 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. // 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) { func Unzip3[A any, B any, C any](tuples []Tuple3[A, B, C]) ([]A, []B, []C) {
size := len(tuples) size := len(tuples)
@@ -121,19 +121,19 @@ type Tuple4[A any, B any, C any, D any] struct {
} }
// Unbox returns values in tuple. // 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) { func (t Tuple4[A, B, C, D]) Unbox() (A, B, C, D) {
return t.FieldA, t.FieldB, t.FieldC, t.FieldD return t.FieldA, t.FieldB, t.FieldC, t.FieldD
} }
// NewTuple4 creates a 4 elemnets tuple from a list of values. // 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] { 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} 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. // 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] { 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)) 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. // 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) { func Unzip4[A any, B any, C any, D any](tuples []Tuple4[A, B, C, D]) ([]A, []B, []C, []D) {
size := len(tuples) 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. // 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) { 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 return t.FieldA, t.FieldB, t.FieldC, t.FieldD, t.FieldE
} }
// NewTuple5 creates a 5 elemnets tuple from a list of values. // 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] { 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} 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. // 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] { 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)) 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. // 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) { 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) 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. // 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) { 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 return t.FieldA, t.FieldB, t.FieldC, t.FieldD, t.FieldE, t.FieldF
} }
// NewTuple6 creates a 6 elemnets tuple from a list of values. // 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] { 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} 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. // 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] { 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)) 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. // 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) { 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) 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. // 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) { 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 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. // 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] { 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} 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. // 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] { 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)) 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. // 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) { 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) 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. // 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) { 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 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. // 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] { 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} 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. // 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] { 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)) 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. // 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) { 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) 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. // 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) { 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 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. // 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] { 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} 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. // 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] { 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)) 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. // 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) { 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) 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. // 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) { 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 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. // 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] { 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} 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. // 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] { 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)) 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. // 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) { 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) size := len(tuples)