diff --git a/README.md b/README.md index ef404ea..6d37678 100644 --- a/README.md +++ b/README.md @@ -791,11 +791,25 @@ import "github.com/duke-git/lancet/v2/function" [[play](https://go.dev/play/p/hbON-Xeyn5N)] - **Pipeline** : takes a list of functions and returns a function whose param will be passed into the functions one by one. [[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/function.md#Pipeline)] - [[play](https://go.dev/play/p/mPdUVvj6HD6)] +- **AcceptIf** : returns another function of the same signature as the apply function but also includes a bool value to indicate success or failure. + [[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/function.md#AcceptIf)] +- **And** : returns a composed predicate that represents the logical AND of a list of predicates. + [[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/function.md#And)] +- **Or** : returns a composed predicate that represents the logical OR of a list of predicates. + [[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/function.md#Or)] +- **Negate** : returns a predicate that represents the logical negation of this predicate. + [[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/function.md#Negate)] +- **Nor** : returns a composed predicate that represents the logical NOR of a list of predicates. + [[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/function.md#Nor)] +- **Nand** : returns a composed predicate that represents the logical Nand of a list of predicates. + [[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/function.md#Nand)] +- **Xnor** : returns a composed predicate that represents the logical XNOR of a list of predicates. + [[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/function.md#Xnor)] - **Watcher** : Watcher is used for record code execution time. can start/stop/reset the watch timer. get the elapsed time of function execution. [[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/function.md#Watcher)] [[play](https://go.dev/play/p/l2yrOpCLd1I)] +

12. Maputil package includes some functions to manipulate map.       index

```go diff --git a/README_zh-CN.md b/README_zh-CN.md index d50d431..9caa9aa 100644 --- a/README_zh-CN.md +++ b/README_zh-CN.md @@ -790,6 +790,20 @@ import "github.com/duke-git/lancet/v2/function" - **Pipeline** : 从右至左执行函数列表。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/function.md#Pipeline)] [[play](https://go.dev/play/p/mPdUVvj6HD6)] +- **AcceptIf** : AcceptIf函数会返回另一个函数,该函数的签名与apply函数相同,但同时还会包含一个布尔值来表示成功或失败。 + [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/function.md#AcceptIf)] +- **And** : 返回一个复合谓词判断函数,该判断函数表示一组谓词的逻辑and操作。 + [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/function.md#And)] +- **Or** : 返回一个复合谓词判断函数,该判断函数表示一组谓词的逻辑or操作。 + [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/function.md#Or)] +- **Negate** : 返回一个谓词函数,该谓词函数表示当前谓词的逻辑否定。 + [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/function.md#Negate)] +- **Nor** : 返回一个复合谓词判断函数,该判断函数表示一组谓词的逻辑非或nor的操作。 + [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/function.md#Nor)] +- **Nand** : 返回一个复合谓词判断函数,该判断函数表示一组谓词的逻辑非与nand的操作。 + [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/function.md#Nand)] +- **Xnor** : 返回一个复合谓词判断函数,该判断函数表示一组谓词的逻辑异或xnor的操作。 + [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/function.md#Xnor)] - **Watcher** : Watcher 用于记录代码执行时间。可以启动/停止/重置手表定时器。获取函数执行的时间。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/function.md#Watcher)] [[play](https://go.dev/play/p/l2yrOpCLd1I)] diff --git a/docs/api/packages/function.md b/docs/api/packages/function.md index d338125..0d45096 100644 --- a/docs/api/packages/function.md +++ b/docs/api/packages/function.md @@ -644,7 +644,7 @@ func main() { ### AcceptIf -

TBD

+

AcceptIf函数会返回另一个函数,该函数的签名与 apply 函数相同,但同时还会包含一个布尔值来表示成功或失败。

函数签名: @@ -664,31 +664,31 @@ import ( func main() { - adder := AcceptIf( - And( - func(x int) bool { - return x > 10 - }, func(x int) bool { - return x%2 == 0 - }), - func(x int) int { - return x + 1 - }, - ) + adder := AcceptIf( + And( + func(x int) bool { + return x > 10 + }, func(x int) bool { + return x%2 == 0 + }), + func(x int) int { + return x + 1 + }, + ) - result, ok := adder(20) - fmt.Println(result) - fmt.Println(ok) + result, ok := adder(20) + fmt.Println(result) + fmt.Println(ok) - result, ok = adder(21) - fmt.Println(result) - fmt.Println(ok) + result, ok = adder(21) + fmt.Println(result) + fmt.Println(ok) - // Output: - // 21 - // true - // 0 - // false + // Output: + // 21 + // true + // 0 + // false } ``` \ No newline at end of file diff --git a/docs/en/api/packages/function.md b/docs/en/api/packages/function.md index 8e798ae..f4cf6d1 100644 --- a/docs/en/api/packages/function.md +++ b/docs/en/api/packages/function.md @@ -665,31 +665,31 @@ import ( func main() { - adder := AcceptIf( - And( - func(x int) bool { - return x > 10 - }, func(x int) bool { - return x%2 == 0 - }), - func(x int) int { - return x + 1 - }, - ) + adder := AcceptIf( + And( + func(x int) bool { + return x > 10 + }, func(x int) bool { + return x%2 == 0 + }), + func(x int) int { + return x + 1 + }, + ) - result, ok := adder(20) - fmt.Println(result) - fmt.Println(ok) + result, ok := adder(20) + fmt.Println(result) + fmt.Println(ok) - result, ok = adder(21) - fmt.Println(result) - fmt.Println(ok) + result, ok = adder(21) + fmt.Println(result) + fmt.Println(ok) - // Output: - // 21 - // true - // 0 - // false + // Output: + // 21 + // true + // 0 + // false } ``` \ No newline at end of file