mirror of
https://github.com/duke-git/lancet.git
synced 2026-02-04 12:52:28 +08:00
Merge branch 'v2' of github.com:duke-git/lancet into v2
This commit is contained in:
@@ -250,7 +250,7 @@ func main() {
|
||||
<b>Signature:</b>
|
||||
|
||||
```go
|
||||
func DifferenceBy[T any](slice []T, comparedSlice []T, iteratee func(index int, t T) T) []T
|
||||
func DifferenceBy[T any](slice []T, comparedSlice []T, iteratee func(index int, item T) T) []T
|
||||
```
|
||||
<b>Example:</b>
|
||||
|
||||
@@ -367,7 +367,7 @@ func main() {
|
||||
<b>Signature:</b>
|
||||
|
||||
```go
|
||||
func Every[T any](slice []T, predicate func(index int, t T) bool) bool
|
||||
func Every[T any](slice []T, predicate func(index int, item T) bool) bool
|
||||
```
|
||||
<b>Example:</b>
|
||||
|
||||
@@ -397,7 +397,7 @@ func main() {
|
||||
<b>Signature:</b>
|
||||
|
||||
```go
|
||||
func Filter[T any](slice []T, predicate func(index int, t T) bool) []T
|
||||
func Filter[T any](slice []T, predicate func(index int, item T) bool) []T
|
||||
```
|
||||
<b>Example:</b>
|
||||
|
||||
@@ -426,7 +426,7 @@ func main() {
|
||||
<b>Signature:</b>
|
||||
|
||||
```go
|
||||
func Find[T any](slice []T, predicate func(index int, t T) bool) (*T, bool)
|
||||
func Find[T any](slice []T, predicate func(index int, item T) bool) (*T, bool)
|
||||
```
|
||||
<b>Example:</b>
|
||||
|
||||
@@ -457,7 +457,7 @@ func main() {
|
||||
<b>Signature:</b>
|
||||
|
||||
```go
|
||||
func FindLast[T any](slice []T, predicate func(index int, t T) bool) (*T, bool)
|
||||
func FindLast[T any](slice []T, predicate func(index int, item T) bool) (*T, bool)
|
||||
```
|
||||
<b>Example:</b>
|
||||
|
||||
@@ -514,7 +514,7 @@ func main() {
|
||||
<b>Signature:</b>
|
||||
|
||||
```go
|
||||
func ForEach[T any](slice []T, iteratee func(index int, t T))
|
||||
func ForEach[T any](slice []T, iteratee func(index int, item T))
|
||||
```
|
||||
<b>Example:</b>
|
||||
|
||||
@@ -543,7 +543,7 @@ func main() {
|
||||
<b>Signature:</b>
|
||||
|
||||
```go
|
||||
func GroupBy[T any](slice []T, groupFn func(index int, t T) bool) ([]T, []T)
|
||||
func GroupBy[T any](slice []T, groupFn func(index int, item T) bool) ([]T, []T)
|
||||
```
|
||||
<b>Example:</b>
|
||||
|
||||
@@ -769,7 +769,7 @@ func main() {
|
||||
<b>Signature:</b>
|
||||
|
||||
```go
|
||||
func Map[T any, U any](slice []T, iteratee func(index int, t T) U) []U
|
||||
func Map[T any, U any](slice []T, iteratee func(index int, item T) U) []U
|
||||
```
|
||||
<b>Example:</b>
|
||||
|
||||
@@ -823,7 +823,7 @@ func main() {
|
||||
<b>Signature:</b>
|
||||
|
||||
```go
|
||||
func Reduce[T any](slice []T, iteratee func(index int, t1, t2 T) T, initial T) T
|
||||
func Reduce[T any](slice []T, iteratee func(index int, item1, item2 T) T, initial T) T
|
||||
```
|
||||
<b>Example:</b>
|
||||
|
||||
@@ -920,7 +920,7 @@ func main() {
|
||||
<b>Signature:</b>
|
||||
|
||||
```go
|
||||
func Some[T any](slice []T, predicate func(index int, t T) bool) bool
|
||||
func Some[T any](slice []T, predicate func(index int, item T) bool) bool
|
||||
```
|
||||
<b>Example:</b>
|
||||
|
||||
|
||||
@@ -250,7 +250,7 @@ func main() {
|
||||
<b>函数签名:</b>
|
||||
|
||||
```go
|
||||
func DifferenceBy[T any](slice []T, comparedSlice []T, iteratee func(index int, t T) T) []T
|
||||
func DifferenceBy[T any](slice []T, comparedSlice []T, iteratee func(index int, item T) T) []T
|
||||
```
|
||||
<b>例子:</b>
|
||||
|
||||
@@ -369,7 +369,7 @@ func main() {
|
||||
<b>函数签名:</b>
|
||||
|
||||
```go
|
||||
func Every[T any](slice []T, predicate func(index int, t T) bool) bool
|
||||
func Every[T any](slice []T, predicate func(index int, item T) bool) bool
|
||||
```
|
||||
<b>例子:</b>
|
||||
|
||||
@@ -394,12 +394,12 @@ func main() {
|
||||
|
||||
|
||||
### <span id="Filter">Filter</span>
|
||||
<p>返回与函数匹配的所有元素。 函数签名应该是 func(index int, value any) bool</p>
|
||||
<p>返回切片中通过predicate函数真值测试的所有元素</p>
|
||||
|
||||
<b>函数签名:</b>
|
||||
|
||||
```go
|
||||
func Filter[T any](slice []T, predicate func(index int, t T) bool) []T
|
||||
func Filter[T any](slice []T, predicate func(index int, item T) bool) []T
|
||||
```
|
||||
<b>例子:</b>
|
||||
|
||||
@@ -423,12 +423,12 @@ func main() {
|
||||
|
||||
|
||||
### <span id="Find">Find</span>
|
||||
<p>遍历slice的元素,返回第一个通过function真值测试的元素</p>
|
||||
<p>遍历切片的元素,返回第一个通过predicate函数真值测试的元素</p>
|
||||
|
||||
<b>函数签名:</b>
|
||||
|
||||
```go
|
||||
func Find[T any](slice []T, predicate func(index int, t T) bool) (*T, bool)
|
||||
func Find[T any](slice []T, predicate func(index int, item T) bool) (*T, bool)
|
||||
```
|
||||
<b>例子:</b>
|
||||
|
||||
@@ -454,12 +454,12 @@ func main() {
|
||||
|
||||
|
||||
### <span id="FindLast">FindLast</span>
|
||||
<p>从头到尾遍历 slice 的元素,返回最后一个通过函数真值测试的元素。</p>
|
||||
<p>从头到尾遍历slice的元素,返回最后一个通过predicate函数真值测试的元素。</p>
|
||||
|
||||
<b>函数签名:</b>
|
||||
|
||||
```go
|
||||
func FindLast[T any](slice []T, predicate func(index int, t T) bool) (*T, bool)
|
||||
func FindLast[T any](slice []T, predicate func(index int, item T) bool) (*T, bool)
|
||||
```
|
||||
<b>例子:</b>
|
||||
|
||||
@@ -511,12 +511,12 @@ func main() {
|
||||
|
||||
|
||||
### <span id="ForEach">ForEach</span>
|
||||
<p>遍历slice的元素并为每个元素调用函数</p>
|
||||
<p>遍历切片的元素并为每个元素调用iteratee函数</p>
|
||||
|
||||
<b>函数签名:</b>
|
||||
|
||||
```go
|
||||
func ForEach[T any](slice []T, iteratee func(index int, t T))
|
||||
func ForEach[T any](slice []T, iteratee func(index int, item T))
|
||||
```
|
||||
<b>例子:</b>
|
||||
|
||||
@@ -545,7 +545,7 @@ func main() {
|
||||
<b>函数签名:</b>
|
||||
|
||||
```go
|
||||
func GroupBy[T any](slice []T, groupFn func(index int, t T) bool) ([]T, []T)
|
||||
func GroupBy[T any](slice []T, groupFn func(index int, item T) bool) ([]T, []T)
|
||||
```
|
||||
<b>例子:</b>
|
||||
|
||||
@@ -768,7 +768,7 @@ func main() {
|
||||
<b>函数签名:</b>
|
||||
|
||||
```go
|
||||
func Map[T any, U any](slice []T, iteratee func(index int, t T) U) []U
|
||||
func Map[T any, U any](slice []T, iteratee func(index int, item T) U) []U
|
||||
```
|
||||
<b>例子:</b>
|
||||
|
||||
@@ -817,12 +817,12 @@ func main() {
|
||||
|
||||
|
||||
### <span id="Reduce">Reduce</span>
|
||||
<p>将slice中的元素依次运行函数,返回运行结果</p>
|
||||
<p>将切片中的元素依次运行iteratee函数,返回运行结果</p>
|
||||
|
||||
<b>函数签名:</b>
|
||||
|
||||
```go
|
||||
func Reduce[T any](slice []T, iteratee func(index int, t1, t2 T) T, initial T) T
|
||||
func Reduce[T any](slice []T, iteratee func(index int, item1, item2 T) T, initial T) T
|
||||
```
|
||||
<b>例子:</b>
|
||||
|
||||
@@ -919,7 +919,7 @@ func main() {
|
||||
<b>函数签名:</b>
|
||||
|
||||
```go
|
||||
func Some[T any](slice []T, predicate func(index int, t T) bool) bool
|
||||
func Some[T any](slice []T, predicate func(index int, item T) bool) bool
|
||||
```
|
||||
<b>例子:</b>
|
||||
|
||||
@@ -1021,7 +1021,7 @@ func main() {
|
||||
|
||||
|
||||
### <span id="Union">Unique</span>
|
||||
<p>从所有给定的切片按顺序创建一个唯一值切片。 使用 == 进行相等比较。</p>
|
||||
<p>从所有给定的切片按顺序创建一个唯一值切片,使用==进行相等比较</p>
|
||||
|
||||
<b>函数签名:</b>
|
||||
|
||||
@@ -1048,7 +1048,7 @@ func main() {
|
||||
|
||||
|
||||
### <span id="UpdateAt">UpdateAt</span>
|
||||
<p>更新索引处的切片元素。 如果 param index < 0 或 index >= len(slice),将返回错误</p>
|
||||
<p>更新索引处的切片元素。 如果index < 0或 index >= len(slice),将返回错误</p>
|
||||
|
||||
<b>函数签名:</b>
|
||||
|
||||
|
||||
@@ -108,7 +108,7 @@ func Difference[T comparable](slice, comparedSlice []T) []T {
|
||||
// DifferenceBy it accepts iteratee which is invoked for each element of slice
|
||||
// and values to generate the criterion by which they're compared.
|
||||
// like lodash.js differenceBy: https://lodash.com/docs/4.17.15#differenceBy,
|
||||
func DifferenceBy[T any](slice []T, comparedSlice []T, iteratee func(index int, t T) T) []T {
|
||||
func DifferenceBy[T any](slice []T, comparedSlice []T, iteratee func(index int, item T) T) []T {
|
||||
orginSliceAfterMap := Map(slice, iteratee)
|
||||
comparedSliceAfterMap := Map(comparedSlice, iteratee)
|
||||
|
||||
@@ -148,7 +148,7 @@ func DifferenceWith[T any](slice []T, comparedSlice []T, comparator func(value,
|
||||
}
|
||||
|
||||
// Every return true if all of the values in the slice pass the predicate function.
|
||||
func Every[T any](slice []T, predicate func(index int, t T) bool) bool {
|
||||
func Every[T any](slice []T, predicate func(index int, item T) bool) bool {
|
||||
if predicate == nil {
|
||||
panic("predicate func is missing")
|
||||
}
|
||||
@@ -164,7 +164,7 @@ func Every[T any](slice []T, predicate func(index int, t T) bool) bool {
|
||||
}
|
||||
|
||||
// None return true if all the values in the slice mismatch the criteria
|
||||
func None[T any](slice []T, predicate func(index int, t T) bool) bool {
|
||||
func None[T any](slice []T, predicate func(index int, item T) bool) bool {
|
||||
if predicate == nil {
|
||||
panic("predicate func is missing")
|
||||
}
|
||||
@@ -180,7 +180,7 @@ func None[T any](slice []T, predicate func(index int, t T) bool) bool {
|
||||
}
|
||||
|
||||
// Some return true if any of the values in the list pass the predicate function.
|
||||
func Some[T any](slice []T, predicate func(index int, t T) bool) bool {
|
||||
func Some[T any](slice []T, predicate func(index int, item T) bool) bool {
|
||||
if predicate == nil {
|
||||
panic("predicate func is missing")
|
||||
}
|
||||
@@ -194,7 +194,7 @@ func Some[T any](slice []T, predicate func(index int, t T) bool) bool {
|
||||
}
|
||||
|
||||
// Filter iterates over elements of slice, returning an slice of all elements pass the predicate function
|
||||
func Filter[T any](slice []T, predicate func(index int, t T) bool) []T {
|
||||
func Filter[T any](slice []T, predicate func(index int, item T) bool) []T {
|
||||
if predicate == nil {
|
||||
panic("predicate func is missing")
|
||||
}
|
||||
@@ -209,7 +209,7 @@ func Filter[T any](slice []T, predicate func(index int, t T) bool) []T {
|
||||
}
|
||||
|
||||
// Count iterates over elements of slice, returns a count of all matched elements
|
||||
func Count[T any](slice []T, predicate func(index int, t T) bool) int {
|
||||
func Count[T any](slice []T, predicate func(index int, item T) bool) int {
|
||||
if predicate == nil {
|
||||
panic("predicate func is missing")
|
||||
}
|
||||
@@ -229,7 +229,7 @@ func Count[T any](slice []T, predicate func(index int, t T) bool) int {
|
||||
}
|
||||
|
||||
// GroupBy iterate over elements of the slice, each element will be group by criteria, returns two slices
|
||||
func GroupBy[T any](slice []T, groupFn func(index int, t T) bool) ([]T, []T) {
|
||||
func GroupBy[T any](slice []T, groupFn func(index int, item T) bool) ([]T, []T) {
|
||||
if groupFn == nil {
|
||||
panic("groupFn func is missing")
|
||||
}
|
||||
@@ -274,7 +274,7 @@ func GroupWith[T any, U comparable](slice []T, iteratee func(T) U) map[U][]T {
|
||||
|
||||
// Find iterates over elements of slice, returning the first one that passes a truth test on predicate function.
|
||||
// If return T is nil then no items matched the predicate func
|
||||
func Find[T any](slice []T, predicate func(index int, t T) bool) (*T, bool) {
|
||||
func Find[T any](slice []T, predicate func(index int, item T) bool) (*T, bool) {
|
||||
if predicate == nil {
|
||||
panic("predicate func is missing")
|
||||
}
|
||||
@@ -300,7 +300,7 @@ func Find[T any](slice []T, predicate func(index int, t T) bool) (*T, bool) {
|
||||
|
||||
// FindLast iterates over elements of slice from end to begin, returning the first one that passes a truth test on predicate function.
|
||||
// If return T is nil then no items matched the predicate func
|
||||
func FindLast[T any](slice []T, predicate func(index int, t T) bool) (*T, bool) {
|
||||
func FindLast[T any](slice []T, predicate func(index int, item T) bool) (*T, bool) {
|
||||
if predicate == nil {
|
||||
panic("predicate func is missing")
|
||||
}
|
||||
@@ -349,7 +349,7 @@ func flattenRecursive(value reflect.Value, result reflect.Value) reflect.Value {
|
||||
}
|
||||
|
||||
// ForEach iterates over elements of slice and invokes function for each element
|
||||
func ForEach[T any](slice []T, iteratee func(index int, t T)) {
|
||||
func ForEach[T any](slice []T, iteratee func(index int, item T)) {
|
||||
if iteratee == nil {
|
||||
panic("iteratee func is missing")
|
||||
}
|
||||
@@ -360,7 +360,7 @@ func ForEach[T any](slice []T, iteratee func(index int, t T)) {
|
||||
}
|
||||
|
||||
// Map creates an slice of values by running each element of slice thru iteratee function.
|
||||
func Map[T any, U any](slice []T, iteratee func(index int, t T) U) []U {
|
||||
func Map[T any, U any](slice []T, iteratee func(index int, item T) U) []U {
|
||||
if iteratee == nil {
|
||||
panic("iteratee func is missing")
|
||||
}
|
||||
@@ -374,7 +374,7 @@ func Map[T any, U any](slice []T, iteratee func(index int, t T) U) []U {
|
||||
}
|
||||
|
||||
// Reduce creates an slice of values by running each element of slice thru iteratee function.
|
||||
func Reduce[T any](slice []T, iteratee func(index int, t1, t2 T) T, initial T) T {
|
||||
func Reduce[T any](slice []T, iteratee func(index int, item1, item2 T) T, initial T) T {
|
||||
if iteratee == nil {
|
||||
panic("iteratee func is missing")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user