From 47ecfbfd5ff30ed0945b764730afc397b9c297cc Mon Sep 17 00:00:00 2001 From: dudaodong Date: Thu, 14 Jul 2022 17:25:47 +0800 Subject: [PATCH] docs: add doc for Flatten function --- docs/slice.md | 28 +++++++++++++++++++++++++++- docs/slice_zh-CN.md | 25 +++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/docs/slice.md b/docs/slice.md index afb148a..3e22335 100644 --- a/docs/slice.md +++ b/docs/slice.md @@ -37,6 +37,7 @@ import ( - [Filter](#Filter) - [Find](#Find) - [FindLast](#FindLast) +- [Flatten](#Flatten) - [FlattenDeep](#FlattenDeep) - [ForEach](#ForEach) @@ -546,6 +547,31 @@ func main() { +### Flatten +

Flatten slice with one level.

+ +Signature: + +```go +func Flatten(slice any) any +``` +Example: + +```go +import ( + "fmt" + "github.com/duke-git/lancet/v2/slice" +) + +func main() { + arr := [][][]string{{{"a", "b"}}, {{"c", "d"}}} + res := slice.Flatten(arr) + fmt.Println(res) //{{"a", "b"}, {"c", "d"}} +} +``` + + + ### FlattenDeep

flattens slice recursive.

@@ -565,7 +591,7 @@ import ( func main() { arr := [][][]string{{{"a", "b"}}, {{"c", "d"}}} res := slice.FlattenDeep(arr) - fmt.Println(res) //[]string{"a", "b", "c", "d"} + fmt.Println(res) //{"a", "b", "c", "d"} } ``` diff --git a/docs/slice_zh-CN.md b/docs/slice_zh-CN.md index 380a6f7..9c81309 100644 --- a/docs/slice_zh-CN.md +++ b/docs/slice_zh-CN.md @@ -37,6 +37,7 @@ import ( - [Filter](#Filter) - [Find](#Find) - [FindLast](#FindLast) +- [Flatten](#Flatten) - [FlattenDeep](#FlattenDeep) - [ForEach](#ForEach) @@ -550,6 +551,30 @@ func main() { ``` +### Flatten +

将切片压平一层

+ +函数签名: + +```go +func Flatten(slice any) any +``` +例子: + +```go +import ( + "fmt" + "github.com/duke-git/lancet/v2/slice" +) + +func main() { + arr := [][][]string{{{"a", "b"}}, {{"c", "d"}}} + res := slice.Flatten(arr) + fmt.Println(res) //{{"a", "b"}, {"c", "d"}} +} +``` + + ### FlattenDeep

flattens slice recursive.