mirror of
https://github.com/duke-git/lancet.git
synced 2026-02-04 12:52:28 +08:00
doc: update doc for slice retry random package
This commit is contained in:
@@ -94,6 +94,9 @@ export const enConfig: LocaleSpecificConfig<DefaultTheme.Config> = {
|
||||
{ text: 'maputil', link: '/en/api/packages/maputil' },
|
||||
{ text: 'netutil', link: '/en/api/packages/netutil' },
|
||||
{ text: 'pointer', link: '/en/api/packages/pointer' },
|
||||
{ text: 'random', link: '/en/api/packages/random' },
|
||||
{ text: 'retry', link: '/en/api/packages/retry' },
|
||||
{ text: 'slice', link: '/en/api/packages/slice' },
|
||||
],
|
||||
},
|
||||
],
|
||||
|
||||
@@ -107,6 +107,9 @@ export const zhConfig: LocaleSpecificConfig<DefaultTheme.Config> = {
|
||||
{ text: 'Map', link: '/api/packages/maputil' },
|
||||
{ text: '网络', link: '/api/packages/netutil' },
|
||||
{ text: '指针', link: '/api/packages/pointer' },
|
||||
{ text: '随机数', link: '/api/packages/random' },
|
||||
{ text: '重试', link: '/api/packages/retry' },
|
||||
{ text: '切片', link: '/api/packages/slice' },
|
||||
],
|
||||
},
|
||||
],
|
||||
|
||||
@@ -34,6 +34,8 @@ import (
|
||||
|
||||
<div STYLE="page-break-after: always;"></div>
|
||||
|
||||
<link rel="stylesheet" type="text/css" href="/styles/api_doc.css">
|
||||
|
||||
## 文档
|
||||
|
||||
### <span id="RandBytes">RandBytes</span>
|
||||
@@ -46,7 +48,7 @@ import (
|
||||
func RandBytes(length int) []byte
|
||||
```
|
||||
|
||||
<b>示例:</b>
|
||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/EkiLESeXf8d)</span></b>
|
||||
|
||||
```go
|
||||
package main
|
||||
@@ -72,7 +74,7 @@ func main() {
|
||||
func RandInt(min, max int) int
|
||||
```
|
||||
|
||||
<b>示例:</b>
|
||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/pXyyAAI5YxD)</span></b>
|
||||
|
||||
```go
|
||||
package main
|
||||
@@ -98,7 +100,7 @@ func main() {
|
||||
func RandString(length int) string
|
||||
```
|
||||
|
||||
<b>示例:</b>
|
||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/W2xvRUXA7Mi)</span></b>
|
||||
|
||||
```go
|
||||
package main
|
||||
@@ -124,7 +126,7 @@ func main() {
|
||||
func RandUpper(length int) string
|
||||
```
|
||||
|
||||
<b>示例:</b>
|
||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/29QfOh0DVuh)</span></b>
|
||||
|
||||
```go
|
||||
package main
|
||||
@@ -150,7 +152,7 @@ func main() {
|
||||
func RandLower(length int) string
|
||||
```
|
||||
|
||||
<b>示例:</b>
|
||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/XJtZ471cmtI)</span></b>
|
||||
|
||||
```go
|
||||
package main
|
||||
@@ -176,7 +178,7 @@ func main() {
|
||||
func RandNumeral(length int) string
|
||||
```
|
||||
|
||||
<b>示例:</b>
|
||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/g4JWVpHsJcf)</span></b>
|
||||
|
||||
```go
|
||||
package main
|
||||
@@ -202,7 +204,7 @@ func main() {
|
||||
func RandNumeralOrLetter(length int) string
|
||||
```
|
||||
|
||||
<b>示例:</b>
|
||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/19CEQvpx2jD)</span></b>
|
||||
|
||||
```go
|
||||
package main
|
||||
@@ -228,7 +230,7 @@ func main() {
|
||||
func UUIdV4() (string, error)
|
||||
```
|
||||
|
||||
<b>示例:</b>
|
||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/_Z9SFmr28ft)</span></b>
|
||||
|
||||
```go
|
||||
package main
|
||||
@@ -257,7 +259,7 @@ func main() {
|
||||
func RandUniqueIntSlice(n, min, max int) []int
|
||||
```
|
||||
|
||||
<b>示例:</b>
|
||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/uBkRSOz73Ec)</span></b>
|
||||
|
||||
```go
|
||||
package main
|
||||
@@ -30,7 +30,9 @@ import (
|
||||
|
||||
<div STYLE="page-break-after: always;"></div>
|
||||
|
||||
## Document 文档
|
||||
<link rel="stylesheet" type="text/css" href="/styles/api_doc.css">
|
||||
|
||||
## 文档
|
||||
|
||||
### <span id="Context">Context</span>
|
||||
|
||||
@@ -42,7 +44,7 @@ import (
|
||||
func Context(ctx context.Context)
|
||||
```
|
||||
|
||||
<b>示例:</b>
|
||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/xnAOOXv9GkS)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -89,7 +91,7 @@ func main() {
|
||||
type RetryFunc func() error
|
||||
```
|
||||
|
||||
<b>示例:</b>
|
||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/nk2XRmagfVF)</span></b>
|
||||
|
||||
```go
|
||||
package main
|
||||
@@ -135,7 +137,7 @@ func main() {
|
||||
func RetryTimes(n uint)
|
||||
```
|
||||
|
||||
<b>示例:</b>
|
||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/ssfVeU2SwLO)</span></b>
|
||||
|
||||
```go
|
||||
package main
|
||||
@@ -178,7 +180,7 @@ func main() {
|
||||
func RetryDuration(d time.Duration)
|
||||
```
|
||||
|
||||
<b>示例:</b>
|
||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/nk2XRmagfVF)</span></b>
|
||||
|
||||
```go
|
||||
package main
|
||||
@@ -224,7 +226,7 @@ func main() {
|
||||
func Retry(retryFunc RetryFunc, opts ...Option) error
|
||||
```
|
||||
|
||||
<b>示例:</b>
|
||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/nk2XRmagfVF)</span></b>
|
||||
|
||||
```go
|
||||
package main
|
||||
@@ -94,6 +94,8 @@ import (
|
||||
|
||||
<div STYLE="page-break-after: always;"></div>
|
||||
|
||||
<link rel="stylesheet" type="text/css" href="/styles/api_doc.css">
|
||||
|
||||
## 文档
|
||||
|
||||
### <span id="AppendIfAbsent">AppendIfAbsent</span>
|
||||
@@ -106,7 +108,7 @@ import (
|
||||
func AppendIfAbsent[T comparable](slice []T, item T) []T
|
||||
```
|
||||
|
||||
<b>示例:</b>
|
||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/GNdv7Jg2Taj)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -137,7 +139,7 @@ func main() {
|
||||
func Contain[T comparable](slice []T, target T) bool
|
||||
```
|
||||
|
||||
<b>示例:</b>
|
||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/_454yEHcNjf)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -168,7 +170,7 @@ func main() {
|
||||
func ContainBy[T any](slice []T, predicate func(item T) bool) bool
|
||||
```
|
||||
|
||||
<b>示例:</b>
|
||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/49tkHfX4GNc)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -213,7 +215,7 @@ func main() {
|
||||
func ContainSubSlice[T comparable](slice, subSlice []T) bool
|
||||
```
|
||||
|
||||
<b>示例:</b>
|
||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/bcuQ3UT6Sev)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -244,7 +246,7 @@ func main() {
|
||||
func Chunk[T any](slice []T, size int) [][]T
|
||||
```
|
||||
|
||||
<b>示例:</b>
|
||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/b4Pou5j2L_C)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -286,7 +288,7 @@ func main() {
|
||||
func Compact[T comparable](slice []T) []T
|
||||
```
|
||||
|
||||
<b>示例:</b>
|
||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/pO5AnxEr3TK)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -323,7 +325,7 @@ func main() {
|
||||
func Concat[T any](slice []T, slices ...[]T) []T
|
||||
```
|
||||
|
||||
<b>示例:</b>
|
||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/gPt-q7zr5mk)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -354,7 +356,7 @@ func main() {
|
||||
func Count[T comparable](slice []T, item T) int
|
||||
```
|
||||
|
||||
<b>示例:</b>
|
||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/Mj4oiEnQvRJ)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -387,7 +389,7 @@ func main() {
|
||||
func CountBy[T any](slice []T, predicate func(index int, item T) bool) int
|
||||
```
|
||||
|
||||
<b>示例:</b>
|
||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/tHOccTMDZCC)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -421,7 +423,7 @@ func main() {
|
||||
func Difference[T comparable](slice, comparedSlice []T) []T
|
||||
```
|
||||
|
||||
<b>示例:</b>
|
||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/VXvadzLzhDa)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -452,7 +454,7 @@ func main() {
|
||||
func DifferenceBy[T comparable](slice []T, comparedSlice []T, iteratee func(index int, item T) T) []T
|
||||
```
|
||||
|
||||
<b>示例:</b>
|
||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/DiivgwM5OnC)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -487,7 +489,7 @@ func main() {
|
||||
func DifferenceWith[T any](slice []T, comparedSlice []T, comparator func(value, otherValue T) bool) []T
|
||||
```
|
||||
|
||||
<b>示例:</b>
|
||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/v2U2deugKuV)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -522,7 +524,7 @@ func main() {
|
||||
func DeleteAt[T any](slice []T, start int, end ...int)
|
||||
```
|
||||
|
||||
<b>示例:</b>
|
||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/pJ-d6MUWcvK)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -557,7 +559,7 @@ func main() {
|
||||
func Drop[T any](slice []T, n int) []T
|
||||
```
|
||||
|
||||
<b>示例:</b>
|
||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/jnPO2yQsT8H)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -594,7 +596,7 @@ func main() {
|
||||
func DropRight[T any](slice []T, n int) []T
|
||||
```
|
||||
|
||||
<b>示例:</b>
|
||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/8bcXvywZezG)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -631,7 +633,7 @@ func main() {
|
||||
func DropWhile[T any](slice []T, predicate func(item T) bool) []T
|
||||
```
|
||||
|
||||
<b>示例:</b>
|
||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/4rt252UV_qs)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -671,7 +673,7 @@ func main() {
|
||||
func DropRightWhile[T any](slice []T, predicate func(item T) bool) []T
|
||||
```
|
||||
|
||||
<b>示例:</b>
|
||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/6wyK3zMY56e)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -713,7 +715,7 @@ func main() {
|
||||
func Every[T any](slice []T, predicate func(index int, item T) bool) bool
|
||||
```
|
||||
|
||||
<b>示例:</b>
|
||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/R8U6Sl-j8cD)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -747,7 +749,7 @@ func main() {
|
||||
func Equal[T comparable](slice1, slice2 []T) bool
|
||||
```
|
||||
|
||||
<b>示例:</b>
|
||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/WcRQJ37ifPa)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -782,7 +784,7 @@ func main() {
|
||||
func EqualWith[T, U any](slice1 []T, slice2 []U, comparator func(T, U) bool) bool
|
||||
```
|
||||
|
||||
<b>示例:</b>
|
||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/b9iygtgsHI1)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -817,7 +819,7 @@ func main() {
|
||||
func Filter[T any](slice []T, predicate func(index int, item T) bool) []T
|
||||
```
|
||||
|
||||
<b>示例:</b>
|
||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/SdPna-7qK4T)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -851,7 +853,7 @@ func main() {
|
||||
func Find[T any](slice []T, predicate func(index int, item T) bool) (*T, bool)
|
||||
```
|
||||
|
||||
<b>示例:</b>
|
||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/CBKeBoHVLgq)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -887,7 +889,7 @@ func main() {
|
||||
func FindBy[T any](slice []T, predicate func(index int, item T) bool) (v T, ok bool)
|
||||
```
|
||||
|
||||
<b>示例:</b>
|
||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/n1lysBYl-GB)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -923,7 +925,7 @@ func main() {
|
||||
func FindLast[T any](slice []T, predicate func(index int, item T) bool) (*T, bool)
|
||||
```
|
||||
|
||||
<b>示例:</b>
|
||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/FFDPV_j7URd)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -959,7 +961,7 @@ func main() {
|
||||
func FindLastBy[T any](slice []T, predicate func(index int, item T) bool) (v T, ok bool)
|
||||
```
|
||||
|
||||
<b>示例:</b>
|
||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/8iqomzyCl_s)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -995,7 +997,7 @@ func main() {
|
||||
func Flatten(slice any) any
|
||||
```
|
||||
|
||||
<b>示例:</b>
|
||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/hYa3cBEevtm)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -1025,7 +1027,7 @@ func main() {
|
||||
func FlattenDeep(slice any) any
|
||||
```
|
||||
|
||||
<b>示例:</b>
|
||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/yjYNHPyCFaF)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -1055,7 +1057,7 @@ func main() {
|
||||
func ForEach[T any](slice []T, iteratee func(index int, item T))
|
||||
```
|
||||
|
||||
<b>示例:</b>
|
||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/DrPaa4YsHRF)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -1090,7 +1092,7 @@ func main() {
|
||||
func ForEachWithBreak[T any](slice []T, iteratee func(index int, item T) bool)
|
||||
```
|
||||
|
||||
<b>示例:</b>
|
||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/qScs39f3D9W)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -1128,7 +1130,7 @@ func main() {
|
||||
func GroupBy[T any](slice []T, groupFn func(index int, item T) bool) ([]T, []T)
|
||||
```
|
||||
|
||||
<b>示例:</b>
|
||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/QVkPxzPR0iA)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -1164,7 +1166,7 @@ func main() {
|
||||
func GroupWith[T any, U comparable](slice []T, iteratee func(T) U) map[U][]T
|
||||
```
|
||||
|
||||
<b>示例:</b>
|
||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/ApCvMNTLO8a)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -1198,7 +1200,7 @@ func main() {
|
||||
func IntSlice(slice any) []int
|
||||
```
|
||||
|
||||
<b>示例:</b>
|
||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/UQDj-on9TGN)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -1227,7 +1229,7 @@ func main() {
|
||||
func InterfaceSlice(slice any) []any
|
||||
```
|
||||
|
||||
<b>示例:</b>
|
||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/FdQXF0Vvqs-)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -1256,7 +1258,7 @@ func main() {
|
||||
func Intersection[T comparable](slices ...[]T) []T
|
||||
```
|
||||
|
||||
<b>示例:</b>
|
||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/anJXfB5wq_t)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -1287,7 +1289,7 @@ func main() {
|
||||
func InsertAt[T any](slice []T, index int, value any) []T
|
||||
```
|
||||
|
||||
<b>示例:</b>
|
||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/hMLNxPEGJVE)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -1327,7 +1329,7 @@ func main() {
|
||||
func IndexOf[T comparable](slice []T, item T) int
|
||||
```
|
||||
|
||||
<b>示例:</b>
|
||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/MRN1f0FpABb)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -1360,7 +1362,7 @@ func main() {
|
||||
func LastIndexOf[T comparable](slice []T, item T) int
|
||||
```
|
||||
|
||||
<b>示例:</b>
|
||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/DokM4cf1IKH)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -1393,7 +1395,7 @@ func main() {
|
||||
func Map[T any, U any](slice []T, iteratee func(index int, item T) U) []U
|
||||
```
|
||||
|
||||
<b>示例:</b>
|
||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/biaTefqPquw)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -1427,7 +1429,7 @@ func main() {
|
||||
func FilterMap[T any, U any](slice []T, iteratee func(index int, item T) (U, bool)) []U
|
||||
```
|
||||
|
||||
<b>示例:</b>
|
||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/J94SZ_9MiIe)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -1464,7 +1466,7 @@ func main() {
|
||||
func FlatMap[T any, U any](slice []T, iteratee func(index int, item T) []U) []U
|
||||
```
|
||||
|
||||
<b>示例:</b>
|
||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/_QARWlWs1N_F)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -1497,7 +1499,7 @@ func main() {
|
||||
func Merge[T any](slices ...[]T) []T
|
||||
```
|
||||
|
||||
<b>示例:</b>
|
||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/lbjFp784r9N)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -1528,7 +1530,7 @@ func main() {
|
||||
func Reverse[T any](slice []T)
|
||||
```
|
||||
|
||||
<b>示例:</b>
|
||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/8uI8f1lwNrQ)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -1558,7 +1560,7 @@ func main() {
|
||||
func Reduce[T any](slice []T, iteratee func(index int, item1, item2 T) T, initial T) T
|
||||
```
|
||||
|
||||
<b>示例:</b>
|
||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/_RfXJJWIsIm)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -1592,7 +1594,7 @@ func main() {
|
||||
func ReduceBy[T any, U any](slice []T, initial U, reducer func(index int, item T, agg U) U) U
|
||||
```
|
||||
|
||||
<b>示例:</b>
|
||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/YKDpLi7gtee)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -1628,7 +1630,7 @@ func main() {
|
||||
func ReduceRight[T any, U any](slice []T, initial U, reducer func(index int, item T, agg U) U) U
|
||||
```
|
||||
|
||||
<b>示例:</b>
|
||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/qT9dZC03A1K)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -1658,7 +1660,7 @@ func main() {
|
||||
func Replace[T comparable](slice []T, old T, new T, n int) []T
|
||||
```
|
||||
|
||||
<b>示例:</b>
|
||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/P5mZp7IhOFo)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -1700,7 +1702,7 @@ func main() {
|
||||
func ReplaceAll[T comparable](slice []T, old T, new T) []T
|
||||
```
|
||||
|
||||
<b>示例:</b>
|
||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/CzqXMsuYUrx)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -1728,7 +1730,7 @@ func main() {
|
||||
func Repeat[T any](item T, n int) []T
|
||||
```
|
||||
|
||||
<b>示例:</b>
|
||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/1CbOmtgILUU)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -1756,7 +1758,7 @@ func main() {
|
||||
func Shuffle[T any](slice []T) []T
|
||||
```
|
||||
|
||||
<b>示例:</b>
|
||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/YHvhnWGU3Ge)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -1785,7 +1787,7 @@ func main() {
|
||||
func IsAscending[T constraints.Ordered](slice []T) bool
|
||||
```
|
||||
|
||||
<b>示例:</b>
|
||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/9CtsFjet4SH)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -1819,7 +1821,7 @@ func main() {
|
||||
func IsDescending[T constraints.Ordered](slice []T) bool
|
||||
```
|
||||
|
||||
<b>示例:</b>
|
||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/U_LljFXma14)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -1853,7 +1855,7 @@ func main() {
|
||||
func IsSorted[T constraints.Ordered](slice []T) bool
|
||||
```
|
||||
|
||||
<b>示例:</b>
|
||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/nCE8wPLwSA-)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -1887,7 +1889,7 @@ func main() {
|
||||
func IsSortedByKey[T any, K constraints.Ordered](slice []T, iteratee func(item T) K) bool
|
||||
```
|
||||
|
||||
<b>示例:</b>
|
||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/tUoGB7DOHI4)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -1927,7 +1929,7 @@ func main() {
|
||||
func Sort[T constraints.Ordered](slice []T, sortOrder ...string)
|
||||
```
|
||||
|
||||
<b>示例:</b>
|
||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/V9AVjzf_4Fk)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -1964,7 +1966,7 @@ func main() {
|
||||
func SortBy[T any](slice []T, less func(a, b T) bool)
|
||||
```
|
||||
|
||||
<b>示例:</b>
|
||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/DAhLQSZEumm)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -2011,7 +2013,7 @@ func main() {
|
||||
func SortByField(slice any, field string, sortType ...string) error
|
||||
```
|
||||
|
||||
<b>示例:</b>
|
||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/fU1prOBP9p1)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -2052,7 +2054,7 @@ func main() {
|
||||
func Some[T any](slice []T, predicate func(index int, item T) bool) bool
|
||||
```
|
||||
|
||||
<b>示例:</b>
|
||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/4pO9Xf9NDGS)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -2086,7 +2088,7 @@ func main() {
|
||||
func StringSlice(slice any) []string
|
||||
```
|
||||
|
||||
<b>示例:</b>
|
||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/W0TZDWCPFcI)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -2115,7 +2117,7 @@ func main() {
|
||||
func SymmetricDifference[T comparable](slices ...[]T) []T
|
||||
```
|
||||
|
||||
<b>示例:</b>
|
||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/1CbOmtgILUU)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -2146,7 +2148,7 @@ func main() {
|
||||
func ToSlice[T any](items ...T) []T
|
||||
```
|
||||
|
||||
<b>示例:</b>
|
||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/YzbzVq5kscN)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -2174,7 +2176,7 @@ func main() {
|
||||
func ToSlicePointer[T any](items ...T) []*T
|
||||
```
|
||||
|
||||
<b>示例:</b>
|
||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/gx4tr6_VXSF)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -2209,7 +2211,7 @@ func main() {
|
||||
func Unique[T comparable](slice []T) []T
|
||||
```
|
||||
|
||||
<b>示例:</b>
|
||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/AXw0R3ZTE6a)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -2236,7 +2238,7 @@ func main() {
|
||||
func UniqueBy[T comparable](slice []T, iteratee func(item T) T) []T
|
||||
```
|
||||
|
||||
<b>示例:</b>
|
||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/UR323iZLDpv)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -2267,7 +2269,7 @@ func main() {
|
||||
func Union[T comparable](slices ...[]T) []T
|
||||
```
|
||||
|
||||
<b>示例:</b>
|
||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/hfXV1iRIZOf)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -2298,7 +2300,7 @@ func main() {
|
||||
func UnionBy[T any, V comparable](predicate func(item T) V, slices ...[]T) []T
|
||||
```
|
||||
|
||||
<b>示例:</b>
|
||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/HGKHfxKQsFi)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -2323,7 +2325,7 @@ func main() {
|
||||
|
||||
### <span id="UpdateAt">UpdateAt</span>
|
||||
|
||||
<p>更新索引处的切片元素。 如果index < 0或 index >= len(slice),将返回错误</p>
|
||||
<p>更新索引处的切片元素。 如果index < 0或 index <= len(slice),将返回错误</p>
|
||||
|
||||
<b>函数签名:</b>
|
||||
|
||||
@@ -2331,7 +2333,7 @@ func main() {
|
||||
func UpdateAt[T any](slice []T, index int, value T) []T
|
||||
```
|
||||
|
||||
<b>示例:</b>
|
||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/f3mh2KloWVm)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -2371,7 +2373,7 @@ func main() {
|
||||
func Without[T comparable](slice []T, items ...T) []T
|
||||
```
|
||||
|
||||
<b>示例:</b>
|
||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/bwhEXEypThg)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -2399,7 +2401,7 @@ func main() {
|
||||
func KeyBy[T any, U comparable](slice []T, iteratee func(item T) U) map[U]T
|
||||
```
|
||||
|
||||
<b>示例:</b>
|
||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/uXod2LWD1Kg)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -2429,7 +2431,7 @@ func main() {
|
||||
func Join[T any](s []T, separator string) string
|
||||
```
|
||||
|
||||
<b>示例:</b>
|
||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/huKzqwNDD7V)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -34,6 +34,8 @@ import (
|
||||
|
||||
<div STYLE="page-break-after: always;"></div>
|
||||
|
||||
<link rel="stylesheet" type="text/css" href="/styles/api_doc.css">
|
||||
|
||||
## Documentation
|
||||
|
||||
### <span id="RandBytes">RandBytes</span>
|
||||
@@ -46,7 +48,7 @@ import (
|
||||
func RandBytes(length int) []byte
|
||||
```
|
||||
|
||||
<b>Example:</b>
|
||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/EkiLESeXf8d)</span></b>
|
||||
|
||||
```go
|
||||
package main
|
||||
@@ -72,7 +74,7 @@ func main() {
|
||||
func RandInt(min, max int) int
|
||||
```
|
||||
|
||||
<b>Example:</b>
|
||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/pXyyAAI5YxD)</span></b>
|
||||
|
||||
```go
|
||||
package main
|
||||
@@ -98,7 +100,7 @@ func main() {
|
||||
func RandString(length int) string
|
||||
```
|
||||
|
||||
<b>Example:</b>
|
||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/W2xvRUXA7Mi)</span></b>
|
||||
|
||||
```go
|
||||
package main
|
||||
@@ -124,7 +126,7 @@ func main() {
|
||||
func RandUpper(length int) string
|
||||
```
|
||||
|
||||
<b>Example:</b>
|
||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/29QfOh0DVuh)</span></b>
|
||||
|
||||
```go
|
||||
package main
|
||||
@@ -150,7 +152,7 @@ func main() {
|
||||
func RandLower(length int) string
|
||||
```
|
||||
|
||||
<b>Example:</b>
|
||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/XJtZ471cmtI)</span></b>
|
||||
|
||||
```go
|
||||
package main
|
||||
@@ -176,7 +178,7 @@ func main() {
|
||||
func RandNumeral(length int) string
|
||||
```
|
||||
|
||||
<b>Example:</b>
|
||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/g4JWVpHsJcf)</span></b>
|
||||
|
||||
```go
|
||||
package main
|
||||
@@ -202,7 +204,7 @@ func main() {
|
||||
func RandNumeralOrLetter(length int) string
|
||||
```
|
||||
|
||||
<b>Example:</b>
|
||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/19CEQvpx2jD)</span></b>
|
||||
|
||||
```go
|
||||
package main
|
||||
@@ -228,7 +230,7 @@ func main() {
|
||||
func UUIdV4() (string, error)
|
||||
```
|
||||
|
||||
<b>Example:</b>
|
||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/_Z9SFmr28ft)</span></b>
|
||||
|
||||
```go
|
||||
package main
|
||||
@@ -258,7 +260,7 @@ func main() {
|
||||
func RandUniqueIntSlice(n, min, max int) []int
|
||||
```
|
||||
|
||||
<b>Example:</b>
|
||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/uBkRSOz73Ec)</span></b>
|
||||
|
||||
```go
|
||||
package main
|
||||
@@ -30,6 +30,8 @@ import (
|
||||
|
||||
<div STYLE="page-break-after: always;"></div>
|
||||
|
||||
<link rel="stylesheet" type="text/css" href="/styles/api_doc.css">
|
||||
|
||||
## Documentation
|
||||
|
||||
### <span id="Context">Context</span>
|
||||
@@ -42,7 +44,7 @@ import (
|
||||
func Context(ctx context.Context)
|
||||
```
|
||||
|
||||
<b>Example:</b>
|
||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/xnAOOXv9GkS)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -89,7 +91,7 @@ func main() {
|
||||
type RetryFunc func() error
|
||||
```
|
||||
|
||||
<b>Example:</b>
|
||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/nk2XRmagfVF)</span></b>
|
||||
|
||||
```go
|
||||
package main
|
||||
@@ -135,7 +137,7 @@ func main() {
|
||||
func RetryTimes(n uint)
|
||||
```
|
||||
|
||||
<b>Example:</b>
|
||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/ssfVeU2SwLO)</span></b>
|
||||
|
||||
```go
|
||||
package main
|
||||
@@ -178,7 +180,7 @@ func main() {
|
||||
func RetryDuration(d time.Duration)
|
||||
```
|
||||
|
||||
<b>Example:</b>
|
||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/nk2XRmagfVF)</span></b>
|
||||
|
||||
```go
|
||||
package main
|
||||
@@ -224,7 +226,7 @@ func main() {
|
||||
func Retry(retryFunc RetryFunc, opts ...Option) error
|
||||
```
|
||||
|
||||
<b>Example:</b>
|
||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/nk2XRmagfVF)</span></b>
|
||||
|
||||
```go
|
||||
package main
|
||||
@@ -94,6 +94,8 @@ import (
|
||||
|
||||
<div STYLE="page-break-after: always;"></div>
|
||||
|
||||
<link rel="stylesheet" type="text/css" href="/styles/api_doc.css">
|
||||
|
||||
## Documentation
|
||||
|
||||
### <span id="AppendIfAbsent">AppendIfAbsent</span>
|
||||
@@ -106,7 +108,7 @@ import (
|
||||
func AppendIfAbsent[T comparable](slice []T, item T) []T
|
||||
```
|
||||
|
||||
<b>Example:</b>
|
||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/xnAOOXv9GkS)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -137,7 +139,7 @@ func main() {
|
||||
func Contain[T comparable](slice []T, target T) bool
|
||||
```
|
||||
|
||||
<b>Example:</b>
|
||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/xnAOOXv9GkS)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -168,7 +170,7 @@ func main() {
|
||||
func ContainBy[T any](slice []T, predicate func(item T) bool) bool
|
||||
```
|
||||
|
||||
<b>Example:</b>
|
||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/xnAOOXv9GkS)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -213,7 +215,7 @@ func main() {
|
||||
func ContainSubSlice[T comparable](slice, subSlice []T) bool
|
||||
```
|
||||
|
||||
<b>Example:</b>
|
||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/bcuQ3UT6Sev)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -244,7 +246,7 @@ func main() {
|
||||
func Chunk[T any](slice []T, size int) [][]T
|
||||
```
|
||||
|
||||
<b>Example:</b>
|
||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/b4Pou5j2L_C)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -286,7 +288,7 @@ func main() {
|
||||
func Compact[T comparable](slice []T) []T
|
||||
```
|
||||
|
||||
<b>Example:</b>
|
||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/pO5AnxEr3TK)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -323,7 +325,7 @@ func main() {
|
||||
func Concat[T any](slice []T, slices ...[]T) []T
|
||||
```
|
||||
|
||||
<b>Example:</b>
|
||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/gPt-q7zr5mk)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -354,7 +356,7 @@ func main() {
|
||||
func Count[T comparable](slice []T, item T) int
|
||||
```
|
||||
|
||||
<b>Example:</b>
|
||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/Mj4oiEnQvRJ)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -387,7 +389,7 @@ func main() {
|
||||
func CountBy[T any](slice []T, predicate func(index int, item T) bool) int
|
||||
```
|
||||
|
||||
<b>Example:</b>
|
||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/tHOccTMDZCC)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -421,7 +423,7 @@ func main() {
|
||||
func Difference[T comparable](slice, comparedSlice []T) []T
|
||||
```
|
||||
|
||||
<b>Example:</b>
|
||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/VXvadzLzhDa)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -452,7 +454,7 @@ func main() {
|
||||
func DifferenceBy[T comparable](slice []T, comparedSlice []T, iteratee func(index int, item T) T) []T
|
||||
```
|
||||
|
||||
<b>Example:</b>
|
||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/DiivgwM5OnC)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -487,7 +489,7 @@ func main() {
|
||||
func DifferenceWith[T any](slice []T, comparedSlice []T, comparator func(value, otherValue T) bool) []T
|
||||
```
|
||||
|
||||
<b>Example:</b>
|
||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/v2U2deugKuV)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -522,7 +524,7 @@ func main() {
|
||||
func DeleteAt[T any](slice []T, start int, end ...int)
|
||||
```
|
||||
|
||||
<b>Example:</b>
|
||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/pJ-d6MUWcvK)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -556,7 +558,7 @@ func main() {
|
||||
func Drop[T any](slice []T, n int) []T
|
||||
```
|
||||
|
||||
<b>Example:</b>
|
||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/jnPO2yQsT8H)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -593,7 +595,7 @@ func main() {
|
||||
func DropRight[T any](slice []T, n int) []T
|
||||
```
|
||||
|
||||
<b>Example:</b>
|
||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/8bcXvywZezG)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -630,7 +632,7 @@ func main() {
|
||||
func DropWhile[T any](slice []T, predicate func(item T) bool) []T
|
||||
```
|
||||
|
||||
<b>Example:</b>
|
||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/4rt252UV_qs)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -670,7 +672,7 @@ func main() {
|
||||
func DropRightWhile[T any](slice []T, predicate func(item T) bool) []T
|
||||
```
|
||||
|
||||
<b>Example:</b>
|
||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/6wyK3zMY56e)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -712,7 +714,7 @@ func main() {
|
||||
func Equal[T comparable](slice1, slice2 []T) bool
|
||||
```
|
||||
|
||||
<b>Example:</b>
|
||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/WcRQJ37ifPa)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -747,7 +749,7 @@ func main() {
|
||||
func EqualWith[T, U any](slice1 []T, slice2 []U, comparator func(T, U) bool) bool
|
||||
```
|
||||
|
||||
<b>Example:</b>
|
||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/b9iygtgsHI1)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -782,7 +784,7 @@ func main() {
|
||||
func Every[T any](slice []T, predicate func(index int, item T) bool) bool
|
||||
```
|
||||
|
||||
<b>Example:</b>
|
||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/R8U6Sl-j8cD)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -816,7 +818,7 @@ func main() {
|
||||
func Filter[T any](slice []T, predicate func(index int, item T) bool) []T
|
||||
```
|
||||
|
||||
<b>Example:</b>
|
||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/SdPna-7qK4T)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -850,7 +852,7 @@ func main() {
|
||||
func Find[T any](slice []T, predicate func(index int, item T) bool) (*T, bool)
|
||||
```
|
||||
|
||||
<b>Example:</b>
|
||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/CBKeBoHVLgq)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -886,7 +888,7 @@ func main() {
|
||||
func FindBy[T any](slice []T, predicate func(index int, item T) bool) (v T, ok bool)
|
||||
```
|
||||
|
||||
<b>Example:</b>
|
||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/n1lysBYl-GB)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -922,7 +924,7 @@ func main() {
|
||||
func FindLast[T any](slice []T, predicate func(index int, item T) bool) (*T, bool)
|
||||
```
|
||||
|
||||
<b>Example:</b>
|
||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/FFDPV_j7URd)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -958,7 +960,7 @@ func main() {
|
||||
func FindLastBy[T any](slice []T, predicate func(index int, item T) bool) (v T, ok bool)
|
||||
```
|
||||
|
||||
<b>Example:</b>
|
||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/8iqomzyCl_s)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -994,7 +996,7 @@ func main() {
|
||||
func Flatten(slice any) any
|
||||
```
|
||||
|
||||
<b>Example:</b>
|
||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/hYa3cBEevtm)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -1024,7 +1026,7 @@ func main() {
|
||||
func FlattenDeep(slice any) any
|
||||
```
|
||||
|
||||
<b>Example:</b>
|
||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/yjYNHPyCFaF)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -1054,7 +1056,7 @@ func main() {
|
||||
func ForEach[T any](slice []T, iteratee func(index int, item T))
|
||||
```
|
||||
|
||||
<b>Example:</b>
|
||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/DrPaa4YsHRF)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -1089,7 +1091,7 @@ func main() {
|
||||
func ForEachWithBreak[T any](slice []T, iteratee func(index int, item T) bool)
|
||||
```
|
||||
|
||||
<b>Example:</b>
|
||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/qScs39f3D9W)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -1127,7 +1129,7 @@ func main() {
|
||||
func GroupBy[T any](slice []T, groupFn func(index int, item T) bool) ([]T, []T)
|
||||
```
|
||||
|
||||
<b>Example:</b>
|
||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/QVkPxzPR0iA)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -1163,7 +1165,7 @@ func main() {
|
||||
func GroupWith[T any, U comparable](slice []T, iteratee func(T) U) map[U][]T
|
||||
```
|
||||
|
||||
<b>Example:</b>
|
||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/ApCvMNTLO8a)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -1197,7 +1199,7 @@ func main() {
|
||||
func IntSlice(slice any) []int
|
||||
```
|
||||
|
||||
<b>Example:</b>
|
||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/UQDj-on9TGN)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -1226,7 +1228,7 @@ func main() {
|
||||
func InterfaceSlice(slice any) []any
|
||||
```
|
||||
|
||||
<b>Example:</b>
|
||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/FdQXF0Vvqs-)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -1255,7 +1257,7 @@ func main() {
|
||||
func Intersection[T comparable](slices ...[]T) []T
|
||||
```
|
||||
|
||||
<b>Example:</b>
|
||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/anJXfB5wq_t)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -1286,7 +1288,7 @@ func main() {
|
||||
func InsertAt[T any](slice []T, index int, value any) []T
|
||||
```
|
||||
|
||||
<b>Example:</b>
|
||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/hMLNxPEGJVE)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -1326,7 +1328,7 @@ func main() {
|
||||
func IndexOf[T comparable](slice []T, item T) int
|
||||
```
|
||||
|
||||
<b>Example:</b>
|
||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/MRN1f0FpABb)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -1359,7 +1361,7 @@ func main() {
|
||||
func LastIndexOf[T comparable](slice []T, item T) int
|
||||
```
|
||||
|
||||
<b>Example:</b>
|
||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/DokM4cf1IKH)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -1392,7 +1394,7 @@ func main() {
|
||||
func Map[T any, U any](slice []T, iteratee func(index int, item T) U) []U
|
||||
```
|
||||
|
||||
<b>Example:</b>
|
||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/biaTefqPquw)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -1426,7 +1428,7 @@ func main() {
|
||||
func FilterMap[T any, U any](slice []T, iteratee func(index int, item T) (U, bool)) []U
|
||||
```
|
||||
|
||||
<b>Example:</b>
|
||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/J94SZ_9MiIe)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -1463,7 +1465,7 @@ func main() {
|
||||
func FlatMap[T any, U any](slice []T, iteratee func(index int, item T) []U) []U
|
||||
```
|
||||
|
||||
<b>Example:</b>
|
||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/_QARWlWs1N_F)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -1496,7 +1498,7 @@ func main() {
|
||||
func Merge[T any](slices ...[]T) []T
|
||||
```
|
||||
|
||||
<b>Example:</b>
|
||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/lbjFp784r9N)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -1527,7 +1529,7 @@ func main() {
|
||||
func Reverse[T any](slice []T)
|
||||
```
|
||||
|
||||
<b>Example:</b>
|
||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/8uI8f1lwNrQ)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -1557,7 +1559,7 @@ func main() {
|
||||
func Reduce[T any](slice []T, iteratee func(index int, item1, item2 T) T, initial T) T
|
||||
```
|
||||
|
||||
<b>Example:</b>
|
||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/_RfXJJWIsIm)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -1591,7 +1593,7 @@ func main() {
|
||||
func ReduceBy[T any, U any](slice []T, initial U, reducer func(index int, item T, agg U) U) U
|
||||
```
|
||||
|
||||
<b>Example:</b>
|
||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/YKDpLi7gtee)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -1627,7 +1629,7 @@ func main() {
|
||||
func ReduceRight[T any, U any](slice []T, initial U, reducer func(index int, item T, agg U) U) U
|
||||
```
|
||||
|
||||
<b>Example:</b>
|
||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/qT9dZC03A1K)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -1657,7 +1659,7 @@ func main() {
|
||||
func Replace[T comparable](slice []T, old T, new T, n int) []T
|
||||
```
|
||||
|
||||
<b>Example:</b>
|
||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/P5mZp7IhOFo)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -1699,7 +1701,7 @@ func main() {
|
||||
func ReplaceAll[T comparable](slice []T, old T, new T) []T
|
||||
```
|
||||
|
||||
<b>Example:</b>
|
||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/CzqXMsuYUrx)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -1727,7 +1729,7 @@ func main() {
|
||||
func Repeat[T any](item T, n int) []T
|
||||
```
|
||||
|
||||
<b>Example:</b>
|
||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/1CbOmtgILUU)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -1755,7 +1757,7 @@ func main() {
|
||||
func Shuffle[T any](slice []T) []T
|
||||
```
|
||||
|
||||
<b>Example:</b>
|
||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/YHvhnWGU3Ge)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -1784,7 +1786,7 @@ func main() {
|
||||
func IsAscending[T constraints.Ordered](slice []T) bool
|
||||
```
|
||||
|
||||
<b>Example:</b>
|
||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/9CtsFjet4SH)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -1818,7 +1820,7 @@ func main() {
|
||||
func IsDescending[T constraints.Ordered](slice []T) bool
|
||||
```
|
||||
|
||||
<b>Example:</b>
|
||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/U_LljFXma14)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -1852,7 +1854,7 @@ func main() {
|
||||
func IsSorted[T constraints.Ordered](slice []T) bool
|
||||
```
|
||||
|
||||
<b>Example:</b>
|
||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/nCE8wPLwSA-)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -1886,7 +1888,7 @@ func main() {
|
||||
func IsSortedByKey[T any, K constraints.Ordered](slice []T, iteratee func(item T) K) bool
|
||||
```
|
||||
|
||||
<b>Example:</b>
|
||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/tUoGB7DOHI4)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -1927,7 +1929,7 @@ func main() {
|
||||
func Sort[T constraints.Ordered](slice []T, sortOrder ...string)
|
||||
```
|
||||
|
||||
<b>Example:</b>
|
||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/V9AVjzf_4Fk)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -1964,7 +1966,7 @@ func main() {
|
||||
func SortBy[T any](slice []T, less func(a, b T) bool)
|
||||
```
|
||||
|
||||
<b>Example:</b>
|
||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/DAhLQSZEumm)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -2011,7 +2013,7 @@ func main() {
|
||||
func SortByField(slice any, field string, sortType ...string) error
|
||||
```
|
||||
|
||||
<b>Example:</b>
|
||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/fU1prOBP9p1)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -2052,7 +2054,7 @@ func main() {
|
||||
func Some[T any](slice []T, predicate func(index int, item T) bool) bool
|
||||
```
|
||||
|
||||
<b>Example:</b>
|
||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/4pO9Xf9NDGS)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -2086,7 +2088,7 @@ func main() {
|
||||
func StringSlice(slice any) []string
|
||||
```
|
||||
|
||||
<b>Example:</b>
|
||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/W0TZDWCPFcI)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -2115,7 +2117,7 @@ func main() {
|
||||
func SymmetricDifference[T comparable](slices ...[]T) []T
|
||||
```
|
||||
|
||||
<b>Example:</b>
|
||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/1CbOmtgILUU)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -2146,7 +2148,7 @@ func main() {
|
||||
func ToSlice[T any](items ...T) []T
|
||||
```
|
||||
|
||||
<b>Example:</b>
|
||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/YzbzVq5kscN)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -2174,7 +2176,7 @@ func main() {
|
||||
func ToSlicePointer[T any](items ...T) []*T
|
||||
```
|
||||
|
||||
<b>Example:</b>
|
||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/gx4tr6_VXSF)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -2209,7 +2211,7 @@ func main() {
|
||||
func Unique[T comparable](slice []T) []T
|
||||
```
|
||||
|
||||
<b>Example:</b>
|
||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/AXw0R3ZTE6a)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -2236,7 +2238,7 @@ func main() {
|
||||
func UniqueBy[T comparable](slice []T, iteratee func(item T) T) []T
|
||||
```
|
||||
|
||||
<b>Example:</b>
|
||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/UR323iZLDpv)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -2267,7 +2269,7 @@ func main() {
|
||||
func Union[T comparable](slices ...[]T) []T
|
||||
```
|
||||
|
||||
<b>Example:</b>
|
||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/hfXV1iRIZOf)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -2298,7 +2300,7 @@ func main() {
|
||||
func UnionBy[T any, V comparable](predicate func(item T) V, slices ...[]T) []T
|
||||
```
|
||||
|
||||
<b>Example:</b>
|
||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/HGKHfxKQsFi)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -2323,7 +2325,7 @@ func main() {
|
||||
|
||||
### <span id="UpdateAt">UpdateAt</span>
|
||||
|
||||
<p>Update the slice element at index. if param index < 0 or index >= len(slice), will return error. </p>
|
||||
<p>Update the slice element at index. if param index < 0 or index <= len(slice), will return error. </p>
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
@@ -2331,7 +2333,7 @@ func main() {
|
||||
func UpdateAt[T any](slice []T, index int, value T) []T
|
||||
```
|
||||
|
||||
<b>Example:</b>
|
||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/f3mh2KloWVm)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -2371,7 +2373,7 @@ func main() {
|
||||
func Without[T comparable](slice []T, items ...T) []T
|
||||
```
|
||||
|
||||
<b>Example:</b>
|
||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/bwhEXEypThg)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -2399,7 +2401,7 @@ func main() {
|
||||
func KeyBy[T any, U comparable](slice []T, iteratee func(item T) U) map[U]T
|
||||
```
|
||||
|
||||
<b>Example:</b>
|
||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/uXod2LWD1Kg)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -2429,7 +2431,7 @@ func main() {
|
||||
func Join[T any](s []T, separator string) string
|
||||
```
|
||||
|
||||
<b>Example:</b>
|
||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/huKzqwNDD7V)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
Reference in New Issue
Block a user