1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-07 22:22:29 +08:00

doc: update doc for condition package

This commit is contained in:
dudaodong
2022-12-31 16:47:18 +08:00
parent b8c6746f31
commit 3ad6f4bd9e
5 changed files with 113 additions and 24 deletions

View File

@@ -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)
- **<big>Bool</big>** : 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)]
- **<big>And</big>** : 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)]
- **<big>Or</big>** : 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)]
- **<big>Xor</big>** : 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)]
- **<big>Nor</big>** : 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)
- **<big>Xnor</big>** : 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)]
- **<big>Nand</big>** : 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)]
- **<big>TernaryOperator</big>** : 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.

View File

@@ -152,14 +152,31 @@ import "github.com/duke-git/lancet/v2/condition"
```
#### Function list:
- **<big>Bool</big>** : 返回传入参数的bool值。
[[doc](https://github.com/duke-git/lancet/blob/main/docs/condition_zh-CN.md#Bool)]
[[play](https://go.dev/play/p/ETzeDJRSvhm)]
- **<big>And</big>** : 逻辑且操作当切仅当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)]
- **<big>Or</big>** : 逻辑或操作当切仅当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)]
- **<big>Xor</big>** : 逻辑异或操作a和b相同返回falsea和b不相同返回true
[[doc](https://github.com/duke-git/lancet/blob/main/docs/condition_zh-CN.md#Xor)]
[[play](https://go.dev/play/p/gObZrW7ZbG8)]
- **<big>Nor</big>** : 异或的取反操作。
[[doc](https://github.com/duke-git/lancet/blob/main/docs/condition_zh-CN.md#Nor)]
[[play](https://go.dev/play/p/g2j08F_zZky)
- **<big>Xnor</big>** : 如果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)]
- **<big>Nand</big>** : 如果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)]
- **<big>TernaryOperator</big>** : 三元运算符。
[[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 转换器包支持一些常见的数据类型转换。

View File

@@ -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)

View File

@@ -25,6 +25,7 @@ import (
- [Or](#Or)
- [Xor](#Generate)
- [Nor](#Nor)
- [Xnor](#Xnor)
- [Nand](#Nand)
- [TernaryOperator](#TernaryOperator)
@@ -120,7 +121,7 @@ func main() {
### <span id="Or">Or</span>
<p>Returns false iff neither a nor b is truthy.</p>
<p>Returns false if neither a nor b is truthy.</p>
<b>Signature:</b>
@@ -148,7 +149,7 @@ func main() {
### <span id="Xor">Xor</span>
<p>Returns true iff a or b but not both is truthy.</p>
<p>Returns true if a or b but not both is truthy.</p>
<b>Signature:</b>
@@ -176,7 +177,7 @@ func main() {
### <span id="Nor">Nor</span>
<p>Returns true iff neither a nor b is truthy.</p>
<p>Returns true if neither a nor b is truthy.</p>
<b>Signature:</b>
@@ -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
}
```
### <span id="Xnor">Xnor</span>
<p>Returns true if both a and b or neither a nor b are truthy.</p>
<b>Signature:</b>
```go
func Xnor[T, U any](a T, b U) bool
```
<b>Example:</b>
```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
}
```
### <span id="Nand">Nand</span>
<p>Returns false iff both a and b are truthy</p>
<p>Returns false if both a and b are truthy</p>
<b>Signature:</b>

View File

@@ -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
}
```
### <span id="Xnor">Xnor</span>
<p>如果a和b都是真的或a和b均是假的则返回true。</p>
<b>函数签名:</b>
```go
func Xnor[T, U any](a T, b U) bool
```
<b>例子:</b>
```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
}
```
### <span id="Nand">Nand</span>
<p>如果a和b都为真返回false否则返回true</p>