mirror of
https://github.com/duke-git/lancet.git
synced 2026-02-04 12:52:28 +08:00
doc: update for release v2.2.8
This commit is contained in:
@@ -1099,10 +1099,16 @@ import "github.com/duke-git/lancet/v2/random"
|
||||
[[play](https://go.dev/play/p/uBkRSOz73Ec)]
|
||||
- **<big>RandSymbolChar</big>** : Generate a random symbol char of specified length.
|
||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/random.md#RandSymbolChar)]
|
||||
[[play](https://go.dev/play/p/Im6ZJxAykOm)]
|
||||
|
||||
- **<big>RandFloat</big>** : Generate a random float64 number between [min, max) with specific precision.
|
||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/random.md#RandFloat)]
|
||||
[[play](https://go.dev/play/p/zbD_tuobJtr)]
|
||||
|
||||
- **<big>RandFloats</big>** : Generate a slice of random float64 numbers of length n that do not repeat.
|
||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/random.md#RandFloats)]
|
||||
[[play](https://go.dev/play/p/I3yndUQ-rhh)]
|
||||
|
||||
|
||||
<h3 id="retry"> 17. Retry package is for executing a function repeatedly until it was successful or canceled by the context. <a href="#index">index</a></h3>
|
||||
|
||||
@@ -1348,6 +1354,8 @@ import "github.com/duke-git/lancet/v2/slice"
|
||||
[[play](https://go.dev/play/p/lkQ3Ri2NQhV)]
|
||||
- **<big>Random</big>** : get a random item of slice, return its index, when slice is empty, return -1.
|
||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/slice.md#Random)]
|
||||
[[play](https://go.dev/play/p/UzpGQptWppw)]
|
||||
|
||||
|
||||
<h3 id="stream"> 19. Stream package implements a sequence of elements supporting sequential and operations. this package is an experiment to explore if stream in go can work as the way java does. its function is very limited. <a href="#index">index</a></h3>
|
||||
|
||||
|
||||
@@ -1100,12 +1100,14 @@ import "github.com/duke-git/lancet/v2/random"
|
||||
[[play](https://go.dev/play/p/uBkRSOz73Ec)]
|
||||
- **<big>RandSymbolChar</big>** : 生成给定长度的随机符号字符串。
|
||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/random.md#RandSymbolChar)]
|
||||
[[play](https://go.dev/play/p/uBkRSOz73Ec)]
|
||||
[[play](https://go.dev/play/p/Im6ZJxAykOm)]
|
||||
- **<big>RandFloat</big>** : 生成随机float64数字,可以指定范围和精度。
|
||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/random.md#RandFloat)]
|
||||
[[play](https://go.dev/play/p/uBkRSOz73Ec)]
|
||||
[[play](https://go.dev/play/p/zbD_tuobJtr)]
|
||||
- **<big>RandFloats</big>** : 生成随机float64数字切片,可以指定长度,范围和精度.
|
||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/random.md#RandFloats)]
|
||||
[[play](https://go.dev/play/p/uBkRSOz73Ec)]
|
||||
|
||||
|
||||
<h3 id="retry"> 17. retry 重试执行函数直到函数运行成功或被 context cancel。 <a href="#index">回到目录</a></h3>
|
||||
|
||||
@@ -1340,7 +1342,6 @@ import "github.com/duke-git/lancet/v2/slice"
|
||||
- **<big>Without</big>** : 创建一个不包括所有给定值的切片。
|
||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/slice.md#Without)]
|
||||
[[play](https://go.dev/play/p/bwhEXEypThg)]
|
||||
- **<big>KeyBy</big>** :将切片每个元素调用函数后转为 map。
|
||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/slice.md#KeyBy)]
|
||||
[[play](https://go.dev/play/p/uXod2LWD1Kg)]
|
||||
- **<big>Join</big>** : 用指定的分隔符链接切片元素。
|
||||
@@ -1351,6 +1352,8 @@ import "github.com/duke-git/lancet/v2/slice"
|
||||
[[play](https://go.dev/play/p/lkQ3Ri2NQhV)]
|
||||
- **<big>Random</big>** : 随机返回切片中元素以及下标, 当切片长度为0时返回下标-1。
|
||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/slice.md#Random)]
|
||||
[[play](https://go.dev/play/p/UzpGQptWppw)]
|
||||
|
||||
|
||||
|
||||
<h3 id="stream"> 19. stream 流,该包仅验证简单的 stream 实现,功能有限。 <a href="#index">回到目录</a></h3>
|
||||
|
||||
@@ -231,7 +231,7 @@ func main() {
|
||||
func RandSymbolChar(length int) string
|
||||
```
|
||||
|
||||
<b>示例:</b>
|
||||
<b>示例:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/Im6ZJxAykOm)</span></b>
|
||||
|
||||
```go
|
||||
package main
|
||||
@@ -243,7 +243,7 @@ import (
|
||||
|
||||
func main() {
|
||||
randStr := random.RandSymbolChar(6)
|
||||
fmt.Println(randStr) //@#(_")
|
||||
fmt.Println(randStr) // 随机特殊字符字符串,例如: @#(_")
|
||||
}
|
||||
```
|
||||
|
||||
@@ -312,7 +312,7 @@ func main() {
|
||||
func RandFloat(min, max float64, precision int) float64
|
||||
```
|
||||
|
||||
<b>实例:</b>
|
||||
<b>实例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/zbD_tuobJtr)</span></b>
|
||||
|
||||
```go
|
||||
package main
|
||||
@@ -338,7 +338,7 @@ func main() {
|
||||
func RandFloats(n int, min, max float64, precision int) []float64
|
||||
```
|
||||
|
||||
<b>实例:</b>
|
||||
<b>实例:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/I3yndUQ-rhh)</span></b>
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
@@ -2501,7 +2501,7 @@ func main() {
|
||||
func Random[T any](slice []T) (val T, idx int)
|
||||
```
|
||||
|
||||
<b>示例:<span style="float:right;display:inline-block;">[运行](TODO)</span></b>
|
||||
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/UzpGQptWppw)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
|
||||
@@ -231,7 +231,7 @@ func main() {
|
||||
func RandSymbolChar(length int) string
|
||||
```
|
||||
|
||||
<b>Example:</b>
|
||||
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/Im6ZJxAykOm)</span></b>
|
||||
|
||||
```go
|
||||
package main
|
||||
@@ -243,7 +243,7 @@ import (
|
||||
|
||||
func main() {
|
||||
randStr := random.RandSymbolChar(6)
|
||||
fmt.Println(randStr) //@#(_")
|
||||
fmt.Println(randStr) // random string like: @#(_")
|
||||
}
|
||||
```
|
||||
|
||||
@@ -313,7 +313,7 @@ func main() {
|
||||
func RandFloat(min, max float64, precision int) float64
|
||||
```
|
||||
|
||||
<b>Example:</b>
|
||||
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/zbD_tuobJtr)</span></b>
|
||||
|
||||
```go
|
||||
package main
|
||||
@@ -339,7 +339,7 @@ func main() {
|
||||
func RandFloats(n int, min, max float64, precision int) []float64
|
||||
```
|
||||
|
||||
<b>Example:</b>
|
||||
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/I3yndUQ-rhh)</span></b>
|
||||
|
||||
```go
|
||||
package main
|
||||
@@ -351,6 +351,6 @@ import (
|
||||
|
||||
func main() {
|
||||
floatNumbers := random.RandFloats(5, 1.0, 5.0, 2)
|
||||
fmt.Println(floatNumber) //[3.42 3.99 1.3 2.38 4.23] (random)
|
||||
fmt.Println(floatNumbers) //[3.42 3.99 1.3 2.38 4.23] (random)
|
||||
}
|
||||
```
|
||||
@@ -2498,7 +2498,7 @@ func main() {
|
||||
func Random[T any](slice []T) (val T, idx int)
|
||||
```
|
||||
|
||||
<b>Example:<span style="float:right;display:inline-block;">[Run](TODO)</span></b>
|
||||
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/UzpGQptWppw)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
|
||||
@@ -230,7 +230,6 @@ func UploadFile(filepath string, server string) (bool, error) {
|
||||
}
|
||||
|
||||
// DownloadFile will download the file exist in url to a local file.
|
||||
// Play: todo
|
||||
func DownloadFile(filepath string, url string) error {
|
||||
resp, err := http.Get(url)
|
||||
if err != nil {
|
||||
|
||||
@@ -41,7 +41,7 @@ func RandInt(min, max int) int {
|
||||
}
|
||||
|
||||
// RandFloat generate random float64 number between [min, max) with specific precision.
|
||||
// Play: todo
|
||||
// Play: https://go.dev/play/p/zbD_tuobJtr
|
||||
func RandFloat(min, max float64, precision int) float64 {
|
||||
if min == max {
|
||||
return min
|
||||
@@ -103,7 +103,7 @@ func RandNumeralOrLetter(length int) string {
|
||||
|
||||
// RandSymbolChar generate a random symbol char of specified length.
|
||||
// symbol chars: !@#$%^&*()_+-=[]{}|;':\",./<>?.
|
||||
// Play: todo
|
||||
// Play: https://go.dev/play/p/Im6ZJxAykOm
|
||||
func RandSymbolChar(length int) string {
|
||||
return random(SymbolChars, length)
|
||||
}
|
||||
@@ -164,7 +164,7 @@ func RandUniqueIntSlice(n, min, max int) []int {
|
||||
}
|
||||
|
||||
// RandFloats generate a slice of random float64 numbers of length n that do not repeat.
|
||||
// Play: todo
|
||||
// Play: https://go.dev/play/p/I3yndUQ-rhh
|
||||
func RandFloats(n int, min, max float64, precision int) []float64 {
|
||||
nums := make([]float64, n)
|
||||
used := make(map[float64]struct{}, n)
|
||||
|
||||
@@ -1232,7 +1232,7 @@ func Partition[T any](slice []T, predicates ...func(item T) bool) [][]T {
|
||||
}
|
||||
|
||||
// Random get a random item of slice, return idx=-1 when slice is empty
|
||||
// Play: todo
|
||||
// Play: https://go.dev/play/p/UzpGQptWppw
|
||||
func Random[T any](slice []T) (val T, idx int) {
|
||||
if len(slice) == 0 {
|
||||
return val, -1
|
||||
|
||||
Reference in New Issue
Block a user