From f09e5217832bac517b255f849d02db6f23990266 Mon Sep 17 00:00:00 2001 From: dudaodong Date: Wed, 22 Mar 2023 21:06:01 +0800 Subject: [PATCH] doc: add go playground demo --- README.md | 6 +++++- README_zh-CN.md | 4 ++++ mathutil/mathutil.go | 4 ++-- slice/slice.go | 1 + 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index f0a731e..e7e70a6 100644 --- a/README.md +++ b/README.md @@ -705,8 +705,11 @@ import "github.com/duke-git/lancet/v2/mathutil" [[play](https://go.dev/play/p/aumarSHIGzP)] - **Range** : Creates a slice of numbers from start with specified count, element step is 1. [[doc](https://github.com/duke-git/lancet/blob/main/docs/mathutil.md#Range)] + [[play](https://go.dev/play/p/9ke2opxa8ZP)] - **RangeWithStep** : Creates a slice of numbers from start to end with specified step. [[doc](https://github.com/duke-git/lancet/blob/main/docs/mathutil.md#Range)] + [[play](https://go.dev/play/p/akLWz0EqOSM)] + ### 13. Netutil package contains functions to get net information and send http request. @@ -921,7 +924,8 @@ import "github.com/duke-git/lancet/v2/slice" [[doc](https://github.com/duke-git/lancet/blob/main/docs/slice.md#ForEach)] [[play](https://go.dev/play/p/DrPaa4YsHRF)] - **ForEachWithBreak** : iterates over elements of slice and invokes function for each element, when iteratee return false, will break the for each loop. - [[doc](https://github.com/duke-git/lancet/blob/main/docs/slice.md#ForEach)] + [[doc](https://github.com/duke-git/lancet/blob/main/docs/slice.md#ForEachWithBreak)] + [[play](https://go.dev/play/p/qScs39f3D9W)] - **GroupBy** : iterate over elements of the slice, each element will be group by criteria, returns two slices. [[doc](https://github.com/duke-git/lancet/blob/main/docs/slice.md#GroupBy)] [[play](https://go.dev/play/p/QVkPxzPR0iA)] diff --git a/README_zh-CN.md b/README_zh-CN.md index 03d99c6..b28bbe9 100644 --- a/README_zh-CN.md +++ b/README_zh-CN.md @@ -704,8 +704,11 @@ import "github.com/duke-git/lancet/v2/mathutil" [[play](https://go.dev/play/p/aumarSHIGzP)] - **Range** : 根据指定的起始值和数量,创建一个数字切片。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/mathutil_zh-CN.md#Range)] + [[play](https://go.dev/play/p/9ke2opxa8ZP)] - **RangeWithStep** : 根据指定的起始值,结束值,步长,创建一个数字切片。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/mathutil_zh-CN.md#RangeWithStep)] + [[play](https://go.dev/play/p/akLWz0EqOSM)] + ### 13. netutil网络包支持获取 ip 地址,发送 http 请求。 @@ -921,6 +924,7 @@ import "github.com/duke-git/lancet/v2/slice" [[play](https://go.dev/play/p/DrPaa4YsHRF)] - **ForEachWithBreak** : 遍历切片的元素并为每个元素调用iteratee函数,当iteratee函数返回false时,终止遍历。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/slice_zh-CN.md#ForEachWithBreak)] + [[play](https://go.dev/play/p/qScs39f3D9W)] - **GroupBy** : 迭代切片的元素,每个元素将按条件分组,返回两个切片。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/slice_zh-CN.md#GroupBy)] [[play](https://go.dev/play/p/QVkPxzPR0iA)] diff --git a/mathutil/mathutil.go b/mathutil/mathutil.go index a1474b3..dc9db5b 100644 --- a/mathutil/mathutil.go +++ b/mathutil/mathutil.go @@ -185,7 +185,7 @@ func Average[T constraints.Integer | constraints.Float](numbers ...T) T { } // Range creates a slice of numbers from start with specified count, element step is 1. -// Play: todo +// Play: https://go.dev/play/p/9ke2opxa8ZP func Range[T constraints.Integer | constraints.Float](start T, count int) []T { size := count if count < 0 { @@ -202,7 +202,7 @@ func Range[T constraints.Integer | constraints.Float](start T, count int) []T { } // RangeWithStep creates a slice of numbers from start to end with specified step. -// Play: todo +// Play: https://go.dev/play/p/akLWz0EqOSM func RangeWithStep[T constraints.Integer | constraints.Float](start, end, step T) []T { result := []T{} diff --git a/slice/slice.go b/slice/slice.go index e4270e0..9f27ca4 100644 --- a/slice/slice.go +++ b/slice/slice.go @@ -423,6 +423,7 @@ func ForEach[T any](slice []T, iteratee func(index int, item T)) { // ForEachWithBreak iterates over elements of slice and invokes function for each element, // when iteratee return false, will break the for each loop. +// Play: https://go.dev/play/p/qScs39f3D9W func ForEachWithBreak[T any](slice []T, iteratee func(index int, item T) bool) { for i, v := range slice { if !iteratee(i, v) {