import{_ as l,o as p,c as o,k as s,a as n,X as a}from"./chunks/framework.6e839c56.js";const C=JSON.parse('{"title":"Condition","description":"","frontmatter":{},"headers":[],"relativePath":"api/packages/condition.md","filePath":"api/packages/condition.md"}'),e={name:"api/packages/condition.md"},t=s("h1",{id:"Condition",tabindex:"-1"},[n("Condition "),s("a",{class:"header-anchor",href:"#Condition","aria-label":'Permalink to "Condition"'},"​")],-1),c=s("p",null,[n("condition包含一些用于条件判断的函数。这个包的实现参考了carlmjohnson的truthy包的实现，更多有用的信息可以在"),s("a",{href:"https://github.com/carlmjohnson/truthy",target:"_blank",rel:"noreferrer"},"truthy"),n("中找到，感谢carlmjohnson。")],-1),r=s("div",{STYLE:"page-break-after: always;"},null,-1),y=s("h2",{id:"源码-",tabindex:"-1"},[n("源码: "),s("a",{class:"header-anchor",href:"#源码-","aria-label":'Permalink to "源码:"'},"​")],-1),F=s("ul",null,[s("li",null,[s("a",{href:"https://github.com/duke-git/lancet/blob/main/condition/condition.go",target:"_blank",rel:"noreferrer"},"https://github.com/duke-git/lancet/blob/main/condition/condition.go")])],-1),i=s("div",{STYLE:"page-break-after: always;"},null,-1),A=a(`<h2 id="用法-" tabindex="-1">用法: <a class="header-anchor" href="#用法-" aria-label="Permalink to &quot;用法:&quot;">​</a></h2><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/condition</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/condition</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span></code></pre></div>`,2),d=s("div",{STYLE:"page-break-after: always;"},null,-1),E=a('<h2 id="目录" tabindex="-1">目录 <a class="header-anchor" href="#目录" aria-label="Permalink to &quot;目录&quot;">​</a></h2><ul><li><a href="#Bool">Bool</a></li><li><a href="#And">And</a></li><li><a href="#Or">Or</a></li><li><a href="#Generate">Xor</a></li><li><a href="#Nor">Nor</a></li><li><a href="#Xnor">Xnor</a></li><li><a href="#Nand">Nand</a></li><li><a href="#TernaryOperator">TernaryOperator</a></li></ul>',2),u=s("div",{STYLE:"page-break-after: always;"},null,-1),B=a(`<link rel="stylesheet" type="text/css" href="/styles/api_doc.css"><h2 id="文档" tabindex="-1">文档 <a class="header-anchor" href="#文档" aria-label="Permalink to &quot;文档&quot;">​</a></h2><h3 id="Bool" tabindex="-1"><span id="Bool">Bool</span> <a class="header-anchor" href="#Bool" aria-label="Permalink to &quot;&lt;span id=&quot;Bool&quot;&gt;Bool&lt;/span&gt;&quot;">​</a></h3><p>返回传入参数的bool值.<br> 如果出入类型参数含有Bool方法, 会调用该方法并返回<br> 如果传入类型参数有IsZero方法, 返回IsZero方法返回值的取反<br> slices和map的length大于0时，返回true，否则返回false<br> 其他类型会判断是否是零值</p><p><b>函数签名:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> Bool[T any](value T) </span><span style="color:#97E1F1;font-style:italic;">bool</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> Bool</span><span style="color:#999999;">[</span><span style="color:#393A34;">T any</span><span style="color:#999999;">](</span><span style="color:#393A34;">value T</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">bool</span></span></code></pre></div><p><b>示例:<span class="run-container"><a href="https://go.dev/play/p/ETzeDJRSvhm" target="_blank" rel="noreferrer">运行</a></span></b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/condition</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// bool</span></span>
<span class="line"><span style="color:#F6F6F4;">    result1 </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> condition.</span><span style="color:#97E1F1;">Bool</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">false</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    result2 </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> condition.</span><span style="color:#97E1F1;">Bool</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">true</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(result1) </span><span style="color:#7B7F8B;">// false</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(result2) </span><span style="color:#7B7F8B;">// true</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// integer</span></span>
<span class="line"><span style="color:#F6F6F4;">    result3 </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> condition.</span><span style="color:#97E1F1;">Bool</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">0</span><span style="color:#F6F6F4;">) </span></span>
<span class="line"><span style="color:#F6F6F4;">    result4 </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> condition.</span><span style="color:#97E1F1;">Bool</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">1</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(result3) </span><span style="color:#7B7F8B;">// false</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(result4) </span><span style="color:#7B7F8B;">// true</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// string</span></span>
<span class="line"><span style="color:#F6F6F4;">    result5 </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> condition.</span><span style="color:#97E1F1;">Bool</span><span style="color:#F6F6F4;">(</span><span style="color:#DEE492;">&quot;&quot;</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    result6 </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> condition.</span><span style="color:#97E1F1;">Bool</span><span style="color:#F6F6F4;">(</span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;"> </span><span style="color:#DEE492;">&quot;</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(result5) </span><span style="color:#7B7F8B;">// false</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(result6) </span><span style="color:#7B7F8B;">// true</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// slice</span></span>
<span class="line"><span style="color:#F6F6F4;">    nums </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> []</span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">{}</span></span>
<span class="line"><span style="color:#F6F6F4;">    result7 </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> condition.</span><span style="color:#97E1F1;">Bool</span><span style="color:#F6F6F4;">(nums)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    nums </span><span style="color:#F286C4;">=</span><span style="color:#F6F6F4;"> </span><span style="color:#97E1F1;">append</span><span style="color:#F6F6F4;">(nums, </span><span style="color:#BF9EEE;">1</span><span style="color:#F6F6F4;">, </span><span style="color:#BF9EEE;">2</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    result8 </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> condition.</span><span style="color:#97E1F1;">Bool</span><span style="color:#F6F6F4;">(nums)</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(result7) </span><span style="color:#7B7F8B;">// false</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(result8) </span><span style="color:#7B7F8B;">// true</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// struct</span></span>
<span class="line"><span style="color:#F6F6F4;">    result9 </span><span style="color:#F286C4;">=</span><span style="color:#F6F6F4;"> condition.</span><span style="color:#97E1F1;">Bool</span><span style="color:#F6F6F4;">(</span><span style="color:#F286C4;">struct</span><span style="color:#F6F6F4;">{}{})</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(result8) </span><span style="color:#7B7F8B;">// false</span></span>
<span class="line"></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// Output:</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// false</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// true</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// false</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// true</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// false</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// true</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// false</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// true</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// false</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/condition</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// bool</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">result1</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> condition</span><span style="color:#999999;">.</span><span style="color:#998418;">Bool</span><span style="color:#999999;">(</span><span style="color:#1E754F;">false</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">result2</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> condition</span><span style="color:#999999;">.</span><span style="color:#998418;">Bool</span><span style="color:#999999;">(</span><span style="color:#1E754F;">true</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">result1</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">// false</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">result2</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">// true</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// integer</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">result3</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> condition</span><span style="color:#999999;">.</span><span style="color:#998418;">Bool</span><span style="color:#999999;">(</span><span style="color:#2F798A;">0</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">result4</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> condition</span><span style="color:#999999;">.</span><span style="color:#998418;">Bool</span><span style="color:#999999;">(</span><span style="color:#2F798A;">1</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">result3</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">// false</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">result4</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">// true</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// string</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">result5</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> condition</span><span style="color:#999999;">.</span><span style="color:#998418;">Bool</span><span style="color:#999999;">(</span><span style="color:#B5695999;">&quot;&quot;</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">result6</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> condition</span><span style="color:#999999;">.</span><span style="color:#998418;">Bool</span><span style="color:#999999;">(</span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">result5</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">// false</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">result6</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">// true</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// slice</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">nums</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> </span><span style="color:#999999;">[]</span><span style="color:#AB5959;">int</span><span style="color:#999999;">{}</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">result7</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> condition</span><span style="color:#999999;">.</span><span style="color:#998418;">Bool</span><span style="color:#999999;">(</span><span style="color:#393A34;">nums</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">nums</span><span style="color:#393A34;"> </span><span style="color:#999999;">=</span><span style="color:#393A34;"> </span><span style="color:#998418;">append</span><span style="color:#999999;">(</span><span style="color:#393A34;">nums</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">1</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">2</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">result8</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> condition</span><span style="color:#999999;">.</span><span style="color:#998418;">Bool</span><span style="color:#999999;">(</span><span style="color:#393A34;">nums</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">result7</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">// false</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">result8</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">// true</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// struct</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">result9</span><span style="color:#393A34;"> </span><span style="color:#999999;">=</span><span style="color:#393A34;"> condition</span><span style="color:#999999;">.</span><span style="color:#998418;">Bool</span><span style="color:#999999;">(</span><span style="color:#1E754F;">struct</span><span style="color:#999999;">{}{})</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">result8</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">// false</span></span>
<span class="line"></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// Output:</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// false</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// true</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// false</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// true</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// false</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// true</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// false</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// true</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// false</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="And" tabindex="-1"><span id="And">And</span> <a class="header-anchor" href="#And" aria-label="Permalink to &quot;&lt;span id=&quot;And&quot;&gt;And&lt;/span&gt;&quot;">​</a></h3><p>逻辑且操作，当切仅当a和b都为true时返回true</p><p><b>函数签名:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> And[T, U any](a T, b U) </span><span style="color:#97E1F1;font-style:italic;">bool</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> And</span><span style="color:#999999;">[</span><span style="color:#393A34;">T</span><span style="color:#999999;">,</span><span style="color:#393A34;"> U any</span><span style="color:#999999;">](</span><span style="color:#393A34;">a T</span><span style="color:#999999;">,</span><span style="color:#393A34;"> b U</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">bool</span></span></code></pre></div><p><b>示例:<span class="run-container"><a href="https://go.dev/play/p/W1SSUmt6pvr" target="_blank" rel="noreferrer">运行</a></span></b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/condition</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(condition.</span><span style="color:#97E1F1;">And</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">0</span><span style="color:#F6F6F4;">, </span><span style="color:#BF9EEE;">1</span><span style="color:#F6F6F4;">)) </span><span style="color:#7B7F8B;">// false</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(condition.</span><span style="color:#97E1F1;">And</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">0</span><span style="color:#F6F6F4;">, </span><span style="color:#DEE492;">&quot;&quot;</span><span style="color:#F6F6F4;">)) </span><span style="color:#7B7F8B;">// false</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(condition.</span><span style="color:#97E1F1;">And</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">0</span><span style="color:#F6F6F4;">, </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">0</span><span style="color:#DEE492;">&quot;</span><span style="color:#F6F6F4;">)) </span><span style="color:#7B7F8B;">// false</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(condition.</span><span style="color:#97E1F1;">And</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">1</span><span style="color:#F6F6F4;">, </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">0</span><span style="color:#DEE492;">&quot;</span><span style="color:#F6F6F4;">)) </span><span style="color:#7B7F8B;">// true</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/condition</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">condition</span><span style="color:#999999;">.</span><span style="color:#998418;">And</span><span style="color:#999999;">(</span><span style="color:#2F798A;">0</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">1</span><span style="color:#999999;">))</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">// false</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">condition</span><span style="color:#999999;">.</span><span style="color:#998418;">And</span><span style="color:#999999;">(</span><span style="color:#2F798A;">0</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;&quot;</span><span style="color:#999999;">))</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">// false</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">condition</span><span style="color:#999999;">.</span><span style="color:#998418;">And</span><span style="color:#999999;">(</span><span style="color:#2F798A;">0</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">0</span><span style="color:#B5695999;">&quot;</span><span style="color:#999999;">))</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">// false</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">condition</span><span style="color:#999999;">.</span><span style="color:#998418;">And</span><span style="color:#999999;">(</span><span style="color:#2F798A;">1</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">0</span><span style="color:#B5695999;">&quot;</span><span style="color:#999999;">))</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">// true</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="Or" tabindex="-1"><span id="Or">Or</span> <a class="header-anchor" href="#Or" aria-label="Permalink to &quot;&lt;span id=&quot;Or&quot;&gt;Or&lt;/span&gt;&quot;">​</a></h3><p>逻辑或操作，当切仅当a和b都为false时返回false</p><p><b>函数签名:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> Or[T, U any](a T, b U) </span><span style="color:#97E1F1;font-style:italic;">bool</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> Or</span><span style="color:#999999;">[</span><span style="color:#393A34;">T</span><span style="color:#999999;">,</span><span style="color:#393A34;"> U any</span><span style="color:#999999;">](</span><span style="color:#393A34;">a T</span><span style="color:#999999;">,</span><span style="color:#393A34;"> b U</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">bool</span></span></code></pre></div><p><b>示例:<span class="run-container"><a href="https://go.dev/play/p/UlQTxHaeEkq" target="_blank" rel="noreferrer">运行</a></span></b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/condition</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(condition.</span><span style="color:#97E1F1;">Or</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">0</span><span style="color:#F6F6F4;">, </span><span style="color:#DEE492;">&quot;&quot;</span><span style="color:#F6F6F4;">)) </span><span style="color:#7B7F8B;">// false</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(condition.</span><span style="color:#97E1F1;">Or</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">0</span><span style="color:#F6F6F4;">, </span><span style="color:#BF9EEE;">1</span><span style="color:#F6F6F4;">)) </span><span style="color:#7B7F8B;">// true</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(condition.</span><span style="color:#97E1F1;">Or</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">0</span><span style="color:#F6F6F4;">, </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">0</span><span style="color:#DEE492;">&quot;</span><span style="color:#F6F6F4;">)) </span><span style="color:#7B7F8B;">// true</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(condition.</span><span style="color:#97E1F1;">Or</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">1</span><span style="color:#F6F6F4;">, </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">0</span><span style="color:#DEE492;">&quot;</span><span style="color:#F6F6F4;">)) </span><span style="color:#7B7F8B;">// true</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/condition</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">condition</span><span style="color:#999999;">.</span><span style="color:#998418;">Or</span><span style="color:#999999;">(</span><span style="color:#2F798A;">0</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;&quot;</span><span style="color:#999999;">))</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">// false</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">condition</span><span style="color:#999999;">.</span><span style="color:#998418;">Or</span><span style="color:#999999;">(</span><span style="color:#2F798A;">0</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">1</span><span style="color:#999999;">))</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">// true</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">condition</span><span style="color:#999999;">.</span><span style="color:#998418;">Or</span><span style="color:#999999;">(</span><span style="color:#2F798A;">0</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">0</span><span style="color:#B5695999;">&quot;</span><span style="color:#999999;">))</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">// true</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">condition</span><span style="color:#999999;">.</span><span style="color:#998418;">Or</span><span style="color:#999999;">(</span><span style="color:#2F798A;">1</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">0</span><span style="color:#B5695999;">&quot;</span><span style="color:#999999;">))</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">// true</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="Xor" tabindex="-1"><span id="Xor">Xor</span> <a class="header-anchor" href="#Xor" aria-label="Permalink to &quot;&lt;span id=&quot;Xor&quot;&gt;Xor&lt;/span&gt;&quot;">​</a></h3><p>逻辑异或操作，a和b相同返回false，a和b不相同返回true</p><p><b>函数签名:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> Xor[T, U any](a T, b U) </span><span style="color:#97E1F1;font-style:italic;">bool</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> Xor</span><span style="color:#999999;">[</span><span style="color:#393A34;">T</span><span style="color:#999999;">,</span><span style="color:#393A34;"> U any</span><span style="color:#999999;">](</span><span style="color:#393A34;">a T</span><span style="color:#999999;">,</span><span style="color:#393A34;"> b U</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">bool</span></span></code></pre></div><p><b>示例:<span class="run-container"><a href="https://go.dev/play/p/gObZrW7ZbG8" target="_blank" rel="noreferrer">运行</a></span></b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/condition</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(condition.</span><span style="color:#97E1F1;">Xor</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">0</span><span style="color:#F6F6F4;">, </span><span style="color:#BF9EEE;">0</span><span style="color:#F6F6F4;">)) </span><span style="color:#7B7F8B;">// false</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(condition.</span><span style="color:#97E1F1;">Xor</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">0</span><span style="color:#F6F6F4;">, </span><span style="color:#BF9EEE;">1</span><span style="color:#F6F6F4;">)) </span><span style="color:#7B7F8B;">// true</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(condition.</span><span style="color:#97E1F1;">Xor</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">1</span><span style="color:#F6F6F4;">, </span><span style="color:#BF9EEE;">0</span><span style="color:#F6F6F4;">)) </span><span style="color:#7B7F8B;">// true</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(condition.</span><span style="color:#97E1F1;">Xor</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">1</span><span style="color:#F6F6F4;">, </span><span style="color:#BF9EEE;">1</span><span style="color:#F6F6F4;">)) </span><span style="color:#7B7F8B;">// false</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/condition</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">condition</span><span style="color:#999999;">.</span><span style="color:#998418;">Xor</span><span style="color:#999999;">(</span><span style="color:#2F798A;">0</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">0</span><span style="color:#999999;">))</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">// false</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">condition</span><span style="color:#999999;">.</span><span style="color:#998418;">Xor</span><span style="color:#999999;">(</span><span style="color:#2F798A;">0</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">1</span><span style="color:#999999;">))</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">// true</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">condition</span><span style="color:#999999;">.</span><span style="color:#998418;">Xor</span><span style="color:#999999;">(</span><span style="color:#2F798A;">1</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">0</span><span style="color:#999999;">))</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">// true</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">condition</span><span style="color:#999999;">.</span><span style="color:#998418;">Xor</span><span style="color:#999999;">(</span><span style="color:#2F798A;">1</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">1</span><span style="color:#999999;">))</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">// false</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="Nor" tabindex="-1"><span id="Nor">Nor</span> <a class="header-anchor" href="#Nor" aria-label="Permalink to &quot;&lt;span id=&quot;Nor&quot;&gt;Nor&lt;/span&gt;&quot;">​</a></h3><p>异或的取反操作</p><p><b>函数签名:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> Nor[T, U any](a T, b U) </span><span style="color:#97E1F1;font-style:italic;">bool</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> Nor</span><span style="color:#999999;">[</span><span style="color:#393A34;">T</span><span style="color:#999999;">,</span><span style="color:#393A34;"> U any</span><span style="color:#999999;">](</span><span style="color:#393A34;">a T</span><span style="color:#999999;">,</span><span style="color:#393A34;"> b U</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">bool</span></span></code></pre></div><p><b>示例:<span class="run-container"><a href="https://go.dev/play/p/g2j08F_zZky" target="_blank" rel="noreferrer">运行</a></span></b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/condition</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(condition.</span><span style="color:#97E1F1;">Nor</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">0</span><span style="color:#F6F6F4;">, </span><span style="color:#BF9EEE;">0</span><span style="color:#F6F6F4;">)) </span><span style="color:#7B7F8B;">// true</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(condition.</span><span style="color:#97E1F1;">Nor</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">0</span><span style="color:#F6F6F4;">, </span><span style="color:#BF9EEE;">1</span><span style="color:#F6F6F4;">)) </span><span style="color:#7B7F8B;">// false</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(condition.</span><span style="color:#97E1F1;">Nor</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">1</span><span style="color:#F6F6F4;">, </span><span style="color:#BF9EEE;">0</span><span style="color:#F6F6F4;">)) </span><span style="color:#7B7F8B;">// false</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(condition.</span><span style="color:#97E1F1;">Nor</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">1</span><span style="color:#F6F6F4;">, </span><span style="color:#BF9EEE;">1</span><span style="color:#F6F6F4;">)) </span><span style="color:#7B7F8B;">// false</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/condition</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">condition</span><span style="color:#999999;">.</span><span style="color:#998418;">Nor</span><span style="color:#999999;">(</span><span style="color:#2F798A;">0</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">0</span><span style="color:#999999;">))</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">// true</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">condition</span><span style="color:#999999;">.</span><span style="color:#998418;">Nor</span><span style="color:#999999;">(</span><span style="color:#2F798A;">0</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">1</span><span style="color:#999999;">))</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">// false</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">condition</span><span style="color:#999999;">.</span><span style="color:#998418;">Nor</span><span style="color:#999999;">(</span><span style="color:#2F798A;">1</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">0</span><span style="color:#999999;">))</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">// false</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">condition</span><span style="color:#999999;">.</span><span style="color:#998418;">Nor</span><span style="color:#999999;">(</span><span style="color:#2F798A;">1</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">1</span><span style="color:#999999;">))</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">// false</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="Xnor" tabindex="-1"><span id="Xnor">Xnor</span> <a class="header-anchor" href="#Xnor" aria-label="Permalink to &quot;&lt;span id=&quot;Xnor&quot;&gt;Xnor&lt;/span&gt;&quot;">​</a></h3><p>如果a和b都是真的或a和b均是假的，则返回true。</p><p><b>函数签名:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> Xnor[T, U any](a T, b U) </span><span style="color:#97E1F1;font-style:italic;">bool</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> Xnor</span><span style="color:#999999;">[</span><span style="color:#393A34;">T</span><span style="color:#999999;">,</span><span style="color:#393A34;"> U any</span><span style="color:#999999;">](</span><span style="color:#393A34;">a T</span><span style="color:#999999;">,</span><span style="color:#393A34;"> b U</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">bool</span></span></code></pre></div><p><b>示例:<span class="run-container"><a href="https://go.dev/play/p/OuDB9g51643" target="_blank" rel="noreferrer">运行</a></span></b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/condition</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(condition.</span><span style="color:#97E1F1;">Xnor</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">0</span><span style="color:#F6F6F4;">, </span><span style="color:#BF9EEE;">0</span><span style="color:#F6F6F4;">)) </span><span style="color:#7B7F8B;">// true</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(condition.</span><span style="color:#97E1F1;">Xnor</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">0</span><span style="color:#F6F6F4;">, </span><span style="color:#BF9EEE;">1</span><span style="color:#F6F6F4;">)) </span><span style="color:#7B7F8B;">// false</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(condition.</span><span style="color:#97E1F1;">Xnor</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">1</span><span style="color:#F6F6F4;">, </span><span style="color:#BF9EEE;">0</span><span style="color:#F6F6F4;">)) </span><span style="color:#7B7F8B;">// false</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(condition.</span><span style="color:#97E1F1;">Xnor</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">1</span><span style="color:#F6F6F4;">, </span><span style="color:#BF9EEE;">1</span><span style="color:#F6F6F4;">)) </span><span style="color:#7B7F8B;">// true</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/condition</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">condition</span><span style="color:#999999;">.</span><span style="color:#998418;">Xnor</span><span style="color:#999999;">(</span><span style="color:#2F798A;">0</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">0</span><span style="color:#999999;">))</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">// true</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">condition</span><span style="color:#999999;">.</span><span style="color:#998418;">Xnor</span><span style="color:#999999;">(</span><span style="color:#2F798A;">0</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">1</span><span style="color:#999999;">))</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">// false</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">condition</span><span style="color:#999999;">.</span><span style="color:#998418;">Xnor</span><span style="color:#999999;">(</span><span style="color:#2F798A;">1</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">0</span><span style="color:#999999;">))</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">// false</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">condition</span><span style="color:#999999;">.</span><span style="color:#998418;">Xnor</span><span style="color:#999999;">(</span><span style="color:#2F798A;">1</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">1</span><span style="color:#999999;">))</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">// true</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="Nand" tabindex="-1"><span id="Nand">Nand</span> <a class="header-anchor" href="#Nand" aria-label="Permalink to &quot;&lt;span id=&quot;Nand&quot;&gt;Nand&lt;/span&gt;&quot;">​</a></h3><p>如果a和b都为真，返回false，否则返回true</p><p><b>函数签名:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> Nand[T, U any](a T, b U) </span><span style="color:#97E1F1;font-style:italic;">bool</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> Nand</span><span style="color:#999999;">[</span><span style="color:#393A34;">T</span><span style="color:#999999;">,</span><span style="color:#393A34;"> U any</span><span style="color:#999999;">](</span><span style="color:#393A34;">a T</span><span style="color:#999999;">,</span><span style="color:#393A34;"> b U</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">bool</span></span></code></pre></div><p><b>示例:<span class="run-container"><a href="https://go.dev/play/p/vSRMLxLIbq8" target="_blank" rel="noreferrer">运行</a></span></b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/condition</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(condition.</span><span style="color:#97E1F1;">Nand</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">0</span><span style="color:#F6F6F4;">, </span><span style="color:#BF9EEE;">0</span><span style="color:#F6F6F4;">)) </span><span style="color:#7B7F8B;">// true</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(condition.</span><span style="color:#97E1F1;">Nand</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">0</span><span style="color:#F6F6F4;">, </span><span style="color:#BF9EEE;">1</span><span style="color:#F6F6F4;">)) </span><span style="color:#7B7F8B;">// true</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(condition.</span><span style="color:#97E1F1;">Nand</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">1</span><span style="color:#F6F6F4;">, </span><span style="color:#BF9EEE;">0</span><span style="color:#F6F6F4;">)) </span><span style="color:#7B7F8B;">// true</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(condition.</span><span style="color:#97E1F1;">Nand</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">1</span><span style="color:#F6F6F4;">, </span><span style="color:#BF9EEE;">1</span><span style="color:#F6F6F4;">)) </span><span style="color:#7B7F8B;">// false</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/condition</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">condition</span><span style="color:#999999;">.</span><span style="color:#998418;">Nand</span><span style="color:#999999;">(</span><span style="color:#2F798A;">0</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">0</span><span style="color:#999999;">))</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">// true</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">condition</span><span style="color:#999999;">.</span><span style="color:#998418;">Nand</span><span style="color:#999999;">(</span><span style="color:#2F798A;">0</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">1</span><span style="color:#999999;">))</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">// true</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">condition</span><span style="color:#999999;">.</span><span style="color:#998418;">Nand</span><span style="color:#999999;">(</span><span style="color:#2F798A;">1</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">0</span><span style="color:#999999;">))</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">// true</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">condition</span><span style="color:#999999;">.</span><span style="color:#998418;">Nand</span><span style="color:#999999;">(</span><span style="color:#2F798A;">1</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">1</span><span style="color:#999999;">))</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">// false</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="TernaryOperator" tabindex="-1"><span id="TernaryOperator">TernaryOperator</span> <a class="header-anchor" href="#TernaryOperator" aria-label="Permalink to &quot;&lt;span id=&quot;TernaryOperator&quot;&gt;TernaryOperator&lt;/span&gt;&quot;">​</a></h3><p>三元运算符</p><p><b>函数签名:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> TernaryOperator[T, U any](isTrue T, ifValue U, elseValue U) U</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> TernaryOperator</span><span style="color:#999999;">[</span><span style="color:#393A34;">T</span><span style="color:#999999;">,</span><span style="color:#393A34;"> U any</span><span style="color:#999999;">](</span><span style="color:#393A34;">isTrue T</span><span style="color:#999999;">,</span><span style="color:#393A34;"> ifValue U</span><span style="color:#999999;">,</span><span style="color:#393A34;"> elseValue U</span><span style="color:#999999;">)</span><span style="color:#393A34;"> U</span></span></code></pre></div><p><b>示例:<span class="run-container"><a href="https://go.dev/play/p/ElllPZY0guT" target="_blank" rel="noreferrer">运行</a></span></b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/condition</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    conditionTrue </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> </span><span style="color:#BF9EEE;">2</span><span style="color:#F6F6F4;"> </span><span style="color:#F286C4;">&gt;</span><span style="color:#F6F6F4;"> </span><span style="color:#BF9EEE;">1</span></span>
<span class="line"><span style="color:#F6F6F4;">    result1 </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> condition.</span><span style="color:#97E1F1;">TernaryOperator</span><span style="color:#F6F6F4;">(conditionTrue, </span><span style="color:#BF9EEE;">0</span><span style="color:#F6F6F4;">, </span><span style="color:#BF9EEE;">1</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    conditionFalse </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> </span><span style="color:#BF9EEE;">2</span><span style="color:#F6F6F4;"> </span><span style="color:#F286C4;">&gt;</span><span style="color:#F6F6F4;"> </span><span style="color:#BF9EEE;">3</span></span>
<span class="line"><span style="color:#F6F6F4;">    result2 </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> condition.</span><span style="color:#97E1F1;">TernaryOperator</span><span style="color:#F6F6F4;">(conditionFalse, </span><span style="color:#BF9EEE;">0</span><span style="color:#F6F6F4;">, </span><span style="color:#BF9EEE;">1</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(result1)</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(result2)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// Output:</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// 0</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// 1</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/condition</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">conditionTrue</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">2</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">&gt;</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">1</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">result1</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> condition</span><span style="color:#999999;">.</span><span style="color:#998418;">TernaryOperator</span><span style="color:#999999;">(</span><span style="color:#393A34;">conditionTrue</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">0</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">1</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">conditionFalse</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">2</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">&gt;</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">3</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">result2</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> condition</span><span style="color:#999999;">.</span><span style="color:#998418;">TernaryOperator</span><span style="color:#999999;">(</span><span style="color:#393A34;">conditionFalse</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">0</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">1</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    </span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">result1</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">result2</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// Output:</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// 0</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// 1</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div>`,50),f=[t,c,r,y,F,i,A,d,E,u,B];function g(h,m,b,v,q,k){return p(),o("div",null,f)}const P=l(e,[["render",g]]);export{C as __pageData,P as default};
