Skip to content

Commit

Permalink
add playground demo
Browse files Browse the repository at this point in the history
  • Loading branch information
duke-git committed Feb 1, 2024
1 parent 6d4fc98 commit fa298b7
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 18 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ import "github.com/duke-git/lancet/v2/fileutil"
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/fileutil.md#WriteCsvFile)]
- **<big>WriteMapsToCsv</big>** : write slice of map to csv file.
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/fileutil.md#WriteMapsToCsv)]
[[play](https://go.dev/play/p/dAXm58Q5U1o)]
[[play](https://go.dev/play/p/umAIomZFV1c)]
- **<big>WriteBytesToFile</big>** : write bytes to target file.
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/fileutil.md#WriteBytesToFile)]
[[play](https://go.dev/play/p/s7QlDxMj3P8)]
Expand Down Expand Up @@ -1182,8 +1182,10 @@ import "github.com/duke-git/lancet/v2/slice"
[[play](https://go.dev/play/p/v2U2deugKuV)]
- **<big>DeleteAt</big>** : delete the element of slice at index.
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/slice.md#DeleteAt)]
[[play](https://go.dev/play/p/800B1dPBYyd)]
- **<big>DeleteRange</big>** : delete the element of slice from start index to end index(exclude).
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/slice.md#DeleteRange)]
[[play](https://go.dev/play/p/945HwiNrnle)]
- **<big>Drop</big>** : drop n elements from the start of a slice.
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/slice.md#Drop)]
[[play](https://go.dev/play/p/jnPO2yQsT8H)]
Expand Down
4 changes: 3 additions & 1 deletion README_zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,7 @@ import "github.com/duke-git/lancet/v2/fileutil"
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/fileutil.md#WriteCsvFile)]
- **<big>WriteMapsToCsv</big>** : 将map切片写入csv文件中。
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/fileutil.md#WriteMapsToCsv)]
[[play](https://go.dev/play/p/dAXm58Q5U1o)]
[[play](https://go.dev/play/p/umAIomZFV1c)]
- **<big>WriteBytesToFile</big>** : 将 bytes 写入文件。
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/fileutil.md#WriteBytesToFile)]
[[play](https://go.dev/play/p/s7QlDxMj3P8)]
Expand Down Expand Up @@ -1181,8 +1181,10 @@ import "github.com/duke-git/lancet/v2/slice"
[[play](https://go.dev/play/p/v2U2deugKuV)]
- **<big>DeleteAt</big>** : 删除切片中指定索引到的元素。
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/slice.md#DeleteAt)]
[[play](https://go.dev/play/p/800B1dPBYyd)]
- **<big>DeleteRange</big>** : 删除切片中指定开始索引到结束索引的元素。
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/slice.md#DeleteRange)]
[[play](https://go.dev/play/p/945HwiNrnle)]
- **<big>Drop</big>** : 从切片头部删除 n 个元素。
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/slice.md#Drop)]
[[play](https://go.dev/play/p/jnPO2yQsT8H)]
Expand Down
4 changes: 2 additions & 2 deletions docs/api/packages/fileutil.md
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,7 @@ func main() {
func WriteMapsToCsv(filepath string, records []map[string]any, appendToExistingFile bool, delimiter rune, headers ...[]string) error
```

<b>示例:</b>
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/umAIomZFV1c)</span></b>

```go
package main
Expand All @@ -782,7 +782,7 @@ func main() {
}

headers := []string{"Name", "Age", "Gender"}
err := WriteMapsToCsv(csvFilePath, records, false, ';', headers)
err := fileutil.WriteMapsToCsv(csvFilePath, records, false, ';', headers)

if err != nil {
log.Fatal(err)
Expand Down
4 changes: 2 additions & 2 deletions docs/api/packages/slice.md
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ func main() {
func DeleteAt[T any](slice []T, index int) []T
```

<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/pJ-d6MUWcvK)</span></b>
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/800B1dPBYyd)</span></b>

```go
import (
Expand Down Expand Up @@ -565,7 +565,7 @@ func main() {
func DeleteRange[T any](slice []T, start, end int) []T
```

<b>示例:</b>
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/945HwiNrnle)</span></b>

```go
import (
Expand Down
3 changes: 1 addition & 2 deletions docs/en/api/packages/fileutil.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ import (
- [Sha](#Sha)
- [ReadCsvFile](#ReadCsvFile)
- [WriteCsvFile](#WriteCsvFile)
- [WriteCsvFile](#WriteCsvFile)
- [WriteMapsToCsv](#WriteMapsToCsv)
- [WriteStringToFile](#WriteStringToFile)
- [WriteBytesToFile](#WriteBytesToFile)
Expand Down Expand Up @@ -760,7 +759,7 @@ func main() {
func WriteMapsToCsv(filepath string, records []map[string]any, appendToExistingFile bool, delimiter rune, headers ...[]string) error
```

<b>Example:</b>
<b>Example:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/umAIomZFV1c)</span></b>

```go
package main
Expand Down
14 changes: 7 additions & 7 deletions docs/en/api/packages/slice.md
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ func main() {
func DeleteAt[T any](slice []T, index int)
```

<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/pJ-d6MUWcvK)</span></b>
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/800B1dPBYyd)</span></b>

```go
import (
Expand Down Expand Up @@ -563,7 +563,7 @@ func main() {
func DeleteRange[T any](slice []T, start, end int) []T
```

<b>Example:</b>
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/945HwiNrnle)</span></b>

```go
import (
Expand All @@ -574,11 +574,11 @@ import (
func main() {
chars := []string{"a", "b", "c", "d", "e"}

result1 := DeleteRange(chars, 0, 0)
result2 := DeleteRange(chars, 0, 1)
result3 := DeleteRange(chars, 0, 3)
result4 := DeleteRange(chars, 0, 4)
result5 := DeleteRange(chars, 0, 5)
result1 := slice.DeleteRange(chars, 0, 0)
result2 := slice.DeleteRange(chars, 0, 1)
result3 := slice.DeleteRange(chars, 0, 3)
result4 := slice.DeleteRange(chars, 0, 4)
result5 := slice.DeleteRange(chars, 0, 5)

fmt.Println(result1)
fmt.Println(result2)
Expand Down
2 changes: 1 addition & 1 deletion fileutil/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,7 @@ func escapeCSVField(field string, delimiter rune) string {
}

// WriteMapsToCsv write slice of map to csv file.
// Play: todo
// Play: https://go.dev/play/p/umAIomZFV1c
// filepath: Path to the CSV file.
// records: Slice of maps to be written. the value of map should be basic type.
// the maps will be sorted by key in alphabeta order, then be written into csv file.
Expand Down
4 changes: 2 additions & 2 deletions slice/slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ func IntSlice(slice any) []int {
}

// DeleteAt delete the element of slice at index.
// Play: https://go.dev/play/p/pJ-d6MUWcvK
// Play: https://go.dev/play/p/800B1dPBYyd
func DeleteAt[T any](slice []T, index int) []T {
if index >= len(slice) {
index = len(slice) - 1
Expand All @@ -633,7 +633,7 @@ func DeleteAt[T any](slice []T, index int) []T {
}

// DeleteRange delete the element of slice from start index to end index(exclude).
// Play: todo
// Play: https://go.dev/play/p/945HwiNrnle
func DeleteRange[T any](slice []T, start, end int) []T {
result := make([]T, 0, len(slice)-(end-start))

Expand Down

0 comments on commit fa298b7

Please sign in to comment.