From 3ad6f4bd9e6af1c8c8599f2062861fc490e75b32 Mon Sep 17 00:00:00 2001 From: dudaodong Date: Sat, 31 Dec 2022 16:47:18 +0800 Subject: [PATCH] doc: update doc for condition package --- README.md | 32 +++++++++++++++++++++++++------- README_zh-CN.md | 31 ++++++++++++++++++++++++------- condition/condition.go | 8 ++++---- docs/condition.md | 37 ++++++++++++++++++++++++++++++++----- docs/condition_zh-CN.md | 29 ++++++++++++++++++++++++++++- 5 files changed, 113 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 02c03a0..0e55407 100644 --- a/README.md +++ b/README.md @@ -154,13 +154,31 @@ import "github.com/duke-git/lancet/v2/condition" #### Function list: -- [Bool](https://github.com/duke-git/lancet/blob/main/docs/condition.md#Bool) -- [And](https://github.com/duke-git/lancet/blob/main/docs/condition.md#And) -- [Or](https://github.com/duke-git/lancet/blob/main/docs/condition.md#Or) -- [Xor](https://github.com/duke-git/lancet/blob/main/docs/condition.md#Xor) -- [Nor](https://github.com/duke-git/lancet/blob/main/docs/condition.md#Nor) -- [Nand](https://github.com/duke-git/lancet/blob/main/docs/condition.md#Nand) -- [TernaryOperator](https://github.com/duke-git/lancet/blob/main/docs/condition.md#TernaryOperator) +- **Bool** : returns the truthy value of anything. + [[doc](https://github.com/duke-git/lancet/blob/main/docs/condition.md#Bool)] + [[play](https://go.dev/play/p/ETzeDJRSvhm)] +- **And** : returns true if both a and b are truthy. + [[doc](https://github.com/duke-git/lancet/blob/main/docs/condition.md#And)] + [[play](https://go.dev/play/p/W1SSUmt6pvr)] +- **Or** : returns false if neither a nor b is truthy. + [[doc](https://github.com/duke-git/lancet/blob/main/docs/condition.md#Or)] + [[play](https://go.dev/play/p/UlQTxHaeEkq)] +- **Xor** : returns true if a or b but not both is truthy. + [[doc](https://github.com/duke-git/lancet/blob/main/docs/condition.md#Xor)] + [[play](https://go.dev/play/p/gObZrW7ZbG8)] +- **Nor** : returns true if neither a nor b is truthy. + [[doc](https://github.com/duke-git/lancet/blob/main/docs/condition.md#Nor)] + [[play](https://go.dev/play/p/g2j08F_zZky) +- **Xnor** : returns true if both a and b or neither a nor b are truthy. + [[doc](https://github.com/duke-git/lancet/blob/main/docs/condition.md#Xnor)] + [[play](https://go.dev/play/p/OuDB9g51643)] +- **Nand** : returns false if both a and b are truthy. + [[doc](https://github.com/duke-git/lancet/blob/main/docs/condition.md#Nand)] + [[play](https://go.dev/play/p/vSRMLxLIbq8)] +- **TernaryOperator** : ternary operator. + [[doc](https://github.com/duke-git/lancet/blob/main/docs/condition.md#TernaryOperator)] + [[play](https://go.dev/play/p/ElllPZY0guT)] + ### 4. Convertor package contains some functions for data convertion. diff --git a/README_zh-CN.md b/README_zh-CN.md index fa57ec1..5767c6a 100644 --- a/README_zh-CN.md +++ b/README_zh-CN.md @@ -152,14 +152,31 @@ import "github.com/duke-git/lancet/v2/condition" ``` #### Function list: +- **Bool** : 返回传入参数的bool值。 + [[doc](https://github.com/duke-git/lancet/blob/main/docs/condition_zh-CN.md#Bool)] + [[play](https://go.dev/play/p/ETzeDJRSvhm)] +- **And** : 逻辑且操作,当切仅当a和b都为true时返回true。 + [[doc](https://github.com/duke-git/lancet/blob/main/docs/condition_zh-CN.md#And)] + [[play](https://go.dev/play/p/W1SSUmt6pvr)] +- **Or** : 逻辑或操作,当切仅当a和b都为false时返回false。 + [[doc](https://github.com/duke-git/lancet/blob/main/docs/condition_zh-CN.md#Or)] + [[play](https://go.dev/play/p/UlQTxHaeEkq)] +- **Xor** : 逻辑异或操作,a和b相同返回false,a和b不相同返回true + [[doc](https://github.com/duke-git/lancet/blob/main/docs/condition_zh-CN.md#Xor)] + [[play](https://go.dev/play/p/gObZrW7ZbG8)] +- **Nor** : 异或的取反操作。 + [[doc](https://github.com/duke-git/lancet/blob/main/docs/condition_zh-CN.md#Nor)] + [[play](https://go.dev/play/p/g2j08F_zZky) +- **Xnor** : 如果a和b都是真的或a和b均是假的,则返回true。 + [[doc](https://github.com/duke-git/lancet/blob/main/docs/condition_zh-CN.md#Xnor)] + [[play](https://go.dev/play/p/OuDB9g51643)] +- **Nand** : 如果a和b都为真,返回false,否则返回true + [[doc](https://github.com/duke-git/lancet/blob/main/docs/condition_zh-CN.md#Nand)] + [[play](https://go.dev/play/p/vSRMLxLIbq8)] +- **TernaryOperator** : 三元运算符。 + [[doc](https://github.com/duke-git/lancet/blob/main/docs/condition_zh-CN.md#TernaryOperator)] + [[play](https://go.dev/play/p/ElllPZY0guT)] -- [Bool](https://github.com/duke-git/lancet/blob/main/docs/condition_zh-CN.md#Bool) -- [And](https://github.com/duke-git/lancet/blob/main/docs/condition_zh-CN.md#And) -- [Or](https://github.com/duke-git/lancet/blob/main/docs/condition_zh-CN.md#Or) -- [Xor](https://github.com/duke-git/lancet/blob/main/docs/condition_zh-CN.md#Xor) -- [Nor](https://github.com/duke-git/lancet/blob/main/docs/condition_zh-CN.md#Nor) -- [Nand](https://github.com/duke-git/lancet/blob/main/docs/condition_zh-CN.md#Nand) -- [TernaryOperator](https://github.com/duke-git/lancet/blob/main/docs/condition_zh-CN.md#TernaryOperator) ### 4. convertor 转换器包支持一些常见的数据类型转换。 diff --git a/condition/condition.go b/condition/condition.go index e169a9a..e2a76c3 100644 --- a/condition/condition.go +++ b/condition/condition.go @@ -40,13 +40,13 @@ func And[T, U any](a T, b U) bool { return Bool(a) && Bool(b) } -// Or returns false iff neither a nor b is truthy. +// Or returns false if neither a nor b is truthy. // Play: https://go.dev/play/p/UlQTxHaeEkq func Or[T, U any](a T, b U) bool { return Bool(a) || Bool(b) } -// Xor returns true iff a or b but not both is truthy. +// Xor returns true if a or b but not both is truthy. // Play: https://go.dev/play/p/gObZrW7ZbG8 func Xor[T, U any](a T, b U) bool { valA := Bool(a) @@ -54,13 +54,13 @@ func Xor[T, U any](a T, b U) bool { return (valA || valB) && valA != valB } -// Nor returns true iff neither a nor b is truthy. +// Nor returns true if neither a nor b is truthy. // Play: https://go.dev/play/p/g2j08F_zZky func Nor[T, U any](a T, b U) bool { return !(Bool(a) || Bool(b)) } -// Xnor returns true iff both a and b or neither a nor b are truthy. +// Xnor returns true if both a and b or neither a nor b are truthy. // Play: https://go.dev/play/p/OuDB9g51643 func Xnor[T, U any](a T, b U) bool { valA := Bool(a) diff --git a/docs/condition.md b/docs/condition.md index 0617757..d3016b6 100644 --- a/docs/condition.md +++ b/docs/condition.md @@ -25,6 +25,7 @@ import ( - [Or](#Or) - [Xor](#Generate) - [Nor](#Nor) +- [Xnor](#Xnor) - [Nand](#Nand) - [TernaryOperator](#TernaryOperator) @@ -120,7 +121,7 @@ func main() { ### Or -

Returns false iff neither a nor b is truthy.

+

Returns false if neither a nor b is truthy.

Signature: @@ -148,7 +149,7 @@ func main() { ### Xor -

Returns true iff a or b but not both is truthy.

+

Returns true if a or b but not both is truthy.

Signature: @@ -176,7 +177,7 @@ func main() { ### Nor -

Returns true iff neither a nor b is truthy.

+

Returns true if neither a nor b is truthy.

Signature: @@ -197,14 +198,40 @@ func main() { fmt.Println(condition.Nor(0, 0)) // true fmt.Println(condition.Nor(0, 1)) // false fmt.Println(condition.Nor(1, 0)) // false - fmt.Println(condition.Nor(1, 1)) // true + fmt.Println(condition.Nor(1, 1)) // false } ``` +### Xnor +

Returns true if both a and b or neither a nor b are truthy.

+ +Signature: + +```go +func Xnor[T, U any](a T, b U) bool +``` +Example: + +```go +package main + +import ( + "fmt" + "github.com/duke-git/lancet/v2/condition" +) + +func main() { + fmt.Println(condition.Xnor(0, 0)) // true + fmt.Println(condition.Xnor(0, 1)) // false + fmt.Println(condition.Xnor(1, 0)) // false + fmt.Println(condition.Xnor(1, 1)) // true +} +``` + ### Nand -

Returns false iff both a and b are truthy

+

Returns false if both a and b are truthy

Signature: diff --git a/docs/condition_zh-CN.md b/docs/condition_zh-CN.md index c4ac86c..abe8134 100644 --- a/docs/condition_zh-CN.md +++ b/docs/condition_zh-CN.md @@ -25,6 +25,7 @@ import ( - [Or](#Or) - [Xor](#Generate) - [Nor](#Nor) +- [Xnor](#Xnor) - [Nand](#Nand) - [TernaryOperator](#TernaryOperator) @@ -196,12 +197,38 @@ func main() { fmt.Println(condition.Nor(0, 0)) // true fmt.Println(condition.Nor(0, 1)) // false fmt.Println(condition.Nor(1, 0)) // false - fmt.Println(condition.Nor(1, 1)) // true + fmt.Println(condition.Nor(1, 1)) // false } ``` +### Xnor +

如果a和b都是真的或a和b均是假的,则返回true。

+ +函数签名: + +```go +func Xnor[T, U any](a T, b U) bool +``` +例子: + +```go +package main + +import ( + "fmt" + "github.com/duke-git/lancet/v2/condition" +) + +func main() { + fmt.Println(condition.Xnor(0, 0)) // true + fmt.Println(condition.Xnor(0, 1)) // false + fmt.Println(condition.Xnor(1, 0)) // false + fmt.Println(condition.Xnor(1, 1)) // true +} +``` + ### Nand

如果a和b都为真,返回false,否则返回true