From 6f458e4367ae39591d2e4b2ad6b3329029208983 Mon Sep 17 00:00:00 2001 From: dudaodong Date: Wed, 30 Nov 2022 12:34:56 +0800 Subject: [PATCH] doc: add doc for NewSetFromSlice --- docs/datastructure/set.md | 27 ++++++++++++++++++++++++++- docs/datastructure/set_zh-CN.md | 26 ++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/docs/datastructure/set.md b/docs/datastructure/set.md index e19db38..22ffe4b 100644 --- a/docs/datastructure/set.md +++ b/docs/datastructure/set.md @@ -22,6 +22,7 @@ import ( ## Index - [NewSet](#NewSet) +- [NewSetFromSlice](#NewSetFromSlice) - [Values](#Values) - [Add](#Add) - [AddIfNotExist](#AddIfNotExist) @@ -46,7 +47,7 @@ import ( ## Documentation ### NewSet -

Make a Set instance

+

Create a set instance

Signature: @@ -71,6 +72,30 @@ func main() { ``` +### NewSetFromSlice +

Create a set from slice

+ +Signature: + +```go +func NewSetFromSlice[T comparable](items []T) Set[T] +``` +Example: + +```go +package main + +import ( + "fmt" + set "github.com/duke-git/lancet/v2/datastructure/set" +) + +func main() { + st := set.NewSetFromSlice([]int{1, 2, 2, 3}) + fmt.Println(st.Values()) //1,2,3 +} +``` + ### Values diff --git a/docs/datastructure/set_zh-CN.md b/docs/datastructure/set_zh-CN.md index 86d5e40..2120f4b 100644 --- a/docs/datastructure/set_zh-CN.md +++ b/docs/datastructure/set_zh-CN.md @@ -22,6 +22,7 @@ import ( ## 目录 - [NewSet](#NewSet) +- [NewSetFromSlice](#NewSetFromSlice) - [Values](#Values) - [Add](#Add) - [AddIfNotExist](#AddIfNotExist) @@ -72,6 +73,31 @@ func main() { +### NewSetFromSlice +

基于切片创建集合

+ +函数签名: + +```go +func NewSetFromSlice[T comparable](items []T) Set[T] +``` +例子: + +```go +package main + +import ( + "fmt" + set "github.com/duke-git/lancet/v2/datastructure/set" +) + +func main() { + st := set.NewSetFromSlice([]int{1, 2, 2, 3}) + fmt.Println(st.Values()) //1,2,3 +} +``` + + ### Values

获取集合中所有元素的切片