mirror of
https://github.com/duke-git/lancet.git
synced 2026-02-13 17:22:27 +08:00
add playground demo
This commit is contained in:
@@ -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)]
|
[[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.
|
- **<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)]
|
[[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.
|
- **<big>WriteBytesToFile</big>** : write bytes to target file.
|
||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/fileutil.md#WriteBytesToFile)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/fileutil.md#WriteBytesToFile)]
|
||||||
[[play](https://go.dev/play/p/s7QlDxMj3P8)]
|
[[play](https://go.dev/play/p/s7QlDxMj3P8)]
|
||||||
@@ -1182,8 +1182,10 @@ import "github.com/duke-git/lancet/v2/slice"
|
|||||||
[[play](https://go.dev/play/p/v2U2deugKuV)]
|
[[play](https://go.dev/play/p/v2U2deugKuV)]
|
||||||
- **<big>DeleteAt</big>** : delete the element of slice at index.
|
- **<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)]
|
[[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).
|
- **<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)]
|
[[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.
|
- **<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)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/slice.md#Drop)]
|
||||||
[[play](https://go.dev/play/p/jnPO2yQsT8H)]
|
[[play](https://go.dev/play/p/jnPO2yQsT8H)]
|
||||||
|
|||||||
@@ -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)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/fileutil.md#WriteCsvFile)]
|
||||||
- **<big>WriteMapsToCsv</big>** : 将map切片写入csv文件中。
|
- **<big>WriteMapsToCsv</big>** : 将map切片写入csv文件中。
|
||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/fileutil.md#WriteMapsToCsv)]
|
[[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 写入文件。
|
- **<big>WriteBytesToFile</big>** : 将 bytes 写入文件。
|
||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/fileutil.md#WriteBytesToFile)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/fileutil.md#WriteBytesToFile)]
|
||||||
[[play](https://go.dev/play/p/s7QlDxMj3P8)]
|
[[play](https://go.dev/play/p/s7QlDxMj3P8)]
|
||||||
@@ -1181,8 +1181,10 @@ import "github.com/duke-git/lancet/v2/slice"
|
|||||||
[[play](https://go.dev/play/p/v2U2deugKuV)]
|
[[play](https://go.dev/play/p/v2U2deugKuV)]
|
||||||
- **<big>DeleteAt</big>** : 删除切片中指定索引到的元素。
|
- **<big>DeleteAt</big>** : 删除切片中指定索引到的元素。
|
||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/slice.md#DeleteAt)]
|
[[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>** : 删除切片中指定开始索引到结束索引的元素。
|
- **<big>DeleteRange</big>** : 删除切片中指定开始索引到结束索引的元素。
|
||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/slice.md#DeleteRange)]
|
[[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 个元素。
|
- **<big>Drop</big>** : 从切片头部删除 n 个元素。
|
||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/slice.md#Drop)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/slice.md#Drop)]
|
||||||
[[play](https://go.dev/play/p/jnPO2yQsT8H)]
|
[[play](https://go.dev/play/p/jnPO2yQsT8H)]
|
||||||
|
|||||||
@@ -759,7 +759,7 @@ func main() {
|
|||||||
func WriteMapsToCsv(filepath string, records []map[string]any, appendToExistingFile bool, delimiter rune, headers ...[]string) error
|
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
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -782,7 +782,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
headers := []string{"Name", "Age", "Gender"}
|
headers := []string{"Name", "Age", "Gender"}
|
||||||
err := WriteMapsToCsv(csvFilePath, records, false, ';', headers)
|
err := fileutil.WriteMapsToCsv(csvFilePath, records, false, ';', headers)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
|
|||||||
@@ -525,7 +525,7 @@ func main() {
|
|||||||
func DeleteAt[T any](slice []T, index int) []T
|
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
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -565,7 +565,7 @@ func main() {
|
|||||||
func DeleteRange[T any](slice []T, start, end int) []T
|
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
|
```go
|
||||||
import (
|
import (
|
||||||
|
|||||||
@@ -45,7 +45,6 @@ import (
|
|||||||
- [Sha](#Sha)
|
- [Sha](#Sha)
|
||||||
- [ReadCsvFile](#ReadCsvFile)
|
- [ReadCsvFile](#ReadCsvFile)
|
||||||
- [WriteCsvFile](#WriteCsvFile)
|
- [WriteCsvFile](#WriteCsvFile)
|
||||||
- [WriteCsvFile](#WriteCsvFile)
|
|
||||||
- [WriteMapsToCsv](#WriteMapsToCsv)
|
- [WriteMapsToCsv](#WriteMapsToCsv)
|
||||||
- [WriteStringToFile](#WriteStringToFile)
|
- [WriteStringToFile](#WriteStringToFile)
|
||||||
- [WriteBytesToFile](#WriteBytesToFile)
|
- [WriteBytesToFile](#WriteBytesToFile)
|
||||||
@@ -760,7 +759,7 @@ func main() {
|
|||||||
func WriteMapsToCsv(filepath string, records []map[string]any, appendToExistingFile bool, delimiter rune, headers ...[]string) error
|
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
|
```go
|
||||||
package main
|
package main
|
||||||
|
|||||||
@@ -524,7 +524,7 @@ func main() {
|
|||||||
func DeleteAt[T any](slice []T, index int)
|
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
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -563,7 +563,7 @@ func main() {
|
|||||||
func DeleteRange[T any](slice []T, start, end int) []T
|
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
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -574,11 +574,11 @@ import (
|
|||||||
func main() {
|
func main() {
|
||||||
chars := []string{"a", "b", "c", "d", "e"}
|
chars := []string{"a", "b", "c", "d", "e"}
|
||||||
|
|
||||||
result1 := DeleteRange(chars, 0, 0)
|
result1 := slice.DeleteRange(chars, 0, 0)
|
||||||
result2 := DeleteRange(chars, 0, 1)
|
result2 := slice.DeleteRange(chars, 0, 1)
|
||||||
result3 := DeleteRange(chars, 0, 3)
|
result3 := slice.DeleteRange(chars, 0, 3)
|
||||||
result4 := DeleteRange(chars, 0, 4)
|
result4 := slice.DeleteRange(chars, 0, 4)
|
||||||
result5 := DeleteRange(chars, 0, 5)
|
result5 := slice.DeleteRange(chars, 0, 5)
|
||||||
|
|
||||||
fmt.Println(result1)
|
fmt.Println(result1)
|
||||||
fmt.Println(result2)
|
fmt.Println(result2)
|
||||||
|
|||||||
@@ -754,7 +754,7 @@ func escapeCSVField(field string, delimiter rune) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// WriteMapsToCsv write slice of map to csv file.
|
// WriteMapsToCsv write slice of map to csv file.
|
||||||
// Play: todo
|
// Play: https://go.dev/play/p/umAIomZFV1c
|
||||||
// filepath: Path to the CSV file.
|
// filepath: Path to the CSV file.
|
||||||
// records: Slice of maps to be written. the value of map should be basic type.
|
// 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.
|
// the maps will be sorted by key in alphabeta order, then be written into csv file.
|
||||||
|
|||||||
@@ -619,7 +619,7 @@ func IntSlice(slice any) []int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// DeleteAt delete the element of slice at index.
|
// 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 {
|
func DeleteAt[T any](slice []T, index int) []T {
|
||||||
if index >= len(slice) {
|
if index >= len(slice) {
|
||||||
index = len(slice) - 1
|
index = len(slice) - 1
|
||||||
@@ -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).
|
// 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 {
|
func DeleteRange[T any](slice []T, start, end int) []T {
|
||||||
result := make([]T, 0, len(slice)-(end-start))
|
result := make([]T, 0, len(slice)-(end-start))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user