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)] +
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