mirror of
https://github.com/duke-git/lancet.git
synced 2026-02-17 11:12:28 +08:00
doc: add go playground demo
This commit is contained in:
@@ -705,8 +705,11 @@ import "github.com/duke-git/lancet/v2/mathutil"
|
|||||||
[[play](https://go.dev/play/p/aumarSHIGzP)]
|
[[play](https://go.dev/play/p/aumarSHIGzP)]
|
||||||
- **<big>Range</big>** : Creates a slice of numbers from start with specified count, element step is 1.
|
- **<big>Range</big>** : 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)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/mathutil.md#Range)]
|
||||||
|
[[play](https://go.dev/play/p/9ke2opxa8ZP)]
|
||||||
- **<big>RangeWithStep</big>** : Creates a slice of numbers from start to end with specified step.
|
- **<big>RangeWithStep</big>** : 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)]
|
[[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.
|
### 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)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/slice.md#ForEach)]
|
||||||
[[play](https://go.dev/play/p/DrPaa4YsHRF)]
|
[[play](https://go.dev/play/p/DrPaa4YsHRF)]
|
||||||
- **<big>ForEachWithBreak</big>** : iterates over elements of slice and invokes function for each element, when iteratee return false, will break the for each loop.
|
- **<big>ForEachWithBreak</big>** : 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)]
|
||||||
- **<big>GroupBy</big>** : iterate over elements of the slice, each element will be group by criteria, returns two slices.
|
- **<big>GroupBy</big>** : 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)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/slice.md#GroupBy)]
|
||||||
[[play](https://go.dev/play/p/QVkPxzPR0iA)]
|
[[play](https://go.dev/play/p/QVkPxzPR0iA)]
|
||||||
|
|||||||
@@ -704,8 +704,11 @@ import "github.com/duke-git/lancet/v2/mathutil"
|
|||||||
[[play](https://go.dev/play/p/aumarSHIGzP)]
|
[[play](https://go.dev/play/p/aumarSHIGzP)]
|
||||||
- **<big>Range</big>** : 根据指定的起始值和数量,创建一个数字切片。
|
- **<big>Range</big>** : 根据指定的起始值和数量,创建一个数字切片。
|
||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/mathutil_zh-CN.md#Range)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/mathutil_zh-CN.md#Range)]
|
||||||
|
[[play](https://go.dev/play/p/9ke2opxa8ZP)]
|
||||||
- **<big>RangeWithStep</big>** : 根据指定的起始值,结束值,步长,创建一个数字切片。
|
- **<big>RangeWithStep</big>** : 根据指定的起始值,结束值,步长,创建一个数字切片。
|
||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/mathutil_zh-CN.md#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 请求。
|
### 13. netutil网络包支持获取 ip 地址,发送 http 请求。
|
||||||
|
|
||||||
@@ -921,6 +924,7 @@ import "github.com/duke-git/lancet/v2/slice"
|
|||||||
[[play](https://go.dev/play/p/DrPaa4YsHRF)]
|
[[play](https://go.dev/play/p/DrPaa4YsHRF)]
|
||||||
- **<big>ForEachWithBreak</big>** : 遍历切片的元素并为每个元素调用iteratee函数,当iteratee函数返回false时,终止遍历。
|
- **<big>ForEachWithBreak</big>** : 遍历切片的元素并为每个元素调用iteratee函数,当iteratee函数返回false时,终止遍历。
|
||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/slice_zh-CN.md#ForEachWithBreak)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/slice_zh-CN.md#ForEachWithBreak)]
|
||||||
|
[[play](https://go.dev/play/p/qScs39f3D9W)]
|
||||||
- **<big>GroupBy</big>** : 迭代切片的元素,每个元素将按条件分组,返回两个切片。
|
- **<big>GroupBy</big>** : 迭代切片的元素,每个元素将按条件分组,返回两个切片。
|
||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/slice_zh-CN.md#GroupBy)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/slice_zh-CN.md#GroupBy)]
|
||||||
[[play](https://go.dev/play/p/QVkPxzPR0iA)]
|
[[play](https://go.dev/play/p/QVkPxzPR0iA)]
|
||||||
|
|||||||
@@ -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.
|
// 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 {
|
func Range[T constraints.Integer | constraints.Float](start T, count int) []T {
|
||||||
size := count
|
size := count
|
||||||
if count < 0 {
|
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.
|
// 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 {
|
func RangeWithStep[T constraints.Integer | constraints.Float](start, end, step T) []T {
|
||||||
result := []T{}
|
result := []T{}
|
||||||
|
|
||||||
|
|||||||
@@ -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,
|
// ForEachWithBreak iterates over elements of slice and invokes function for each element,
|
||||||
// when iteratee return false, will break the for each loop.
|
// 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) {
|
func ForEachWithBreak[T any](slice []T, iteratee func(index int, item T) bool) {
|
||||||
for i, v := range slice {
|
for i, v := range slice {
|
||||||
if !iteratee(i, v) {
|
if !iteratee(i, v) {
|
||||||
|
|||||||
Reference in New Issue
Block a user