Skip to content

Commit

Permalink
doc: update for release v2.2.8
Browse files Browse the repository at this point in the history
  • Loading branch information
duke-git committed Dec 11, 2023
1 parent c5297ec commit 9632006
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 19 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. &nbsp; &nbsp; &nbsp; &nbsp;<a href="#index">index</a></h3>

Expand Down Expand Up @@ -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. &nbsp; &nbsp; &nbsp; &nbsp;<a href="#index">index</a></h3>

Expand Down
9 changes: 6 additions & 3 deletions README_zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -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。&nbsp; &nbsp; &nbsp; &nbsp;<a href="#index">回到目录</a></h3>

Expand Down Expand Up @@ -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>** : 用指定的分隔符链接切片元素。
Expand All @@ -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 实现,功能有限。&nbsp; &nbsp; &nbsp; &nbsp;<a href="#index">回到目录</a></h3>
Expand Down
8 changes: 4 additions & 4 deletions docs/api/packages/random.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -243,7 +243,7 @@ import (

func main() {
randStr := random.RandSymbolChar(6)
fmt.Println(randStr) //@#(_")
fmt.Println(randStr) // 随机特殊字符字符串,例如: @#(_")
}
```

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs/api/packages/slice.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
10 changes: 5 additions & 5 deletions docs/en/api/packages/random.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -243,7 +243,7 @@ import (

func main() {
randStr := random.RandSymbolChar(6)
fmt.Println(randStr) //@#(_")
fmt.Println(randStr) // random string like: @#(_")
}
```

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)
}
```
2 changes: 1 addition & 1 deletion docs/en/api/packages/slice.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
1 change: 0 additions & 1 deletion netutil/net.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions random/random.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion slice/slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9632006

Please sign in to comment.