diff options
Diffstat (limited to 'docs/content/en/functions/compare')
-rw-r--r-- | docs/content/en/functions/compare/Conditional.md | 41 | ||||
-rw-r--r-- | docs/content/en/functions/compare/Default.md | 48 | ||||
-rw-r--r-- | docs/content/en/functions/compare/Eq.md | 27 | ||||
-rw-r--r-- | docs/content/en/functions/compare/Ge.md | 32 | ||||
-rw-r--r-- | docs/content/en/functions/compare/Gt.md | 32 | ||||
-rw-r--r-- | docs/content/en/functions/compare/Le.md | 32 | ||||
-rw-r--r-- | docs/content/en/functions/compare/Lt.md | 32 | ||||
-rw-r--r-- | docs/content/en/functions/compare/Ne.md | 27 | ||||
-rw-r--r-- | docs/content/en/functions/compare/_index.md | 12 |
9 files changed, 0 insertions, 283 deletions
diff --git a/docs/content/en/functions/compare/Conditional.md b/docs/content/en/functions/compare/Conditional.md deleted file mode 100644 index 6d693770d..000000000 --- a/docs/content/en/functions/compare/Conditional.md +++ /dev/null @@ -1,41 +0,0 @@ ---- -title: compare.Conditional -description: Returns one of two arguments depending on the value of the control argument. -categories: [] -keywords: [] -action: - aliases: [cond] - related: - - functions/compare/Default - returnType: any - signatures: [compare.Conditional CONTROL ARG1 ARG2] -aliases: [/functions/cond] ---- - -The CONTROL argument is a boolean value that indicates whether the function should return ARG1 or ARG2. If CONTROL is `true`, the function returns ARG1. Otherwise, the function returns ARG2. - -```go-html-template -{{ $qty := 42 }} -{{ cond (le $qty 3) "few" "many" }} → many -``` - -The CONTROL argument must be either `true` or `false`. To cast a non-boolean value to boolean, pass it through the `not` operator twice. - -```go-html-template -{{ cond (42 | not | not) "truthy" "falsy" }} → truthy -{{ cond ("" | not | not) "truthy" "falsy" }} → falsy -``` - -{{% note %}} -Unlike [ternary operators] in other languages, the `cond` function does not perform [short-circuit evaluation]. The function evaluates both ARG1 and ARG2, regardless of the CONTROL value. - -[short-circuit evaluation]: https://en.wikipedia.org/wiki/Short-circuit_evaluation -[ternary operators]: https://en.wikipedia.org/wiki/Ternary_conditional_operator -{{% /note %}} - -Due to the absence of short-circuit evaluation, these examples throw an error: - -```go-html-template -{{ cond true "true" (div 1 0) }} -{{ cond false (div 1 0) "false" }} -``` diff --git a/docs/content/en/functions/compare/Default.md b/docs/content/en/functions/compare/Default.md deleted file mode 100644 index 1e6bd7968..000000000 --- a/docs/content/en/functions/compare/Default.md +++ /dev/null @@ -1,48 +0,0 @@ ---- -title: compare.Default -description: Returns the second argument if set, else the first argument. -keywords: [] -action: - aliases: [default] - related: - - functions/compare/Conditional - - functions/go-template/Or - returnType: any - signatures: [compare.Default DEFAULT INPUT] -aliases: [/functions/default] ---- - -The `default` function returns the second argument if set, else the first argument. - -{{% note %}} -When the second argument is the boolean `false` value, the `default` function returns `false`. All _other_ falsy values are considered unset. - -{{% include "functions/go-template/_common/truthy-falsy.md" %}} - -To set a default value based on truthiness, use the [`or`] operator instead. - -[`or`]: /functions/go-template/or -{{% /note %}} - -The `default` function returns the second argument if set: - -```go-html-template -{{ default 42 1 }} → 1 -{{ default 42 "foo" }} → foo -{{ default 42 (dict "k" "v") }} → map[k:v] -{{ default 42 (slice "a" "b") }} → [a b] -{{ default 42 true }} → true - -<!-- As noted above, the boolean "false" is considered set --> -{{ default 42 false }} → false -``` - -The `default` function returns the first argument if the second argument is not set: - -```go-html-template -{{ default 42 0 }} → 42 -{{ default 42 "" }} → 42 -{{ default 42 dict }} → 42 -{{ default 42 slice }} → 42 -{{ default 42 <nil> }} → 42 -``` diff --git a/docs/content/en/functions/compare/Eq.md b/docs/content/en/functions/compare/Eq.md deleted file mode 100644 index 49350e676..000000000 --- a/docs/content/en/functions/compare/Eq.md +++ /dev/null @@ -1,27 +0,0 @@ ---- -title: compare.Eq -description: Returns the boolean truth of arg1 == arg2 || arg1 == arg3. -categories: [] -keywords: [] -action: - aliases: [eq] - related: - - functions/compare/Ge - - functions/compare/Gt - - functions/compare/Le - - functions/compare/Lt - - functions/compare/Ne - returnType: bool - signatures: ['compare.Eq ARG1 ARG2 [ARG...]'] -aliases: [/functions/eq] ---- - -```go-html-template -{{ eq 1 1 }} → true -{{ eq 1 2 }} → false - -{{ eq 1 1 1 }} → true -{{ eq 1 1 2 }} → true -{{ eq 1 2 1 }} → true -{{ eq 1 2 2 }} → false -``` diff --git a/docs/content/en/functions/compare/Ge.md b/docs/content/en/functions/compare/Ge.md deleted file mode 100644 index 479ecf990..000000000 --- a/docs/content/en/functions/compare/Ge.md +++ /dev/null @@ -1,32 +0,0 @@ ---- -title: compare.Ge -description: Returns the boolean truth of arg1 >= arg2 && arg1 >= arg3. -categories: [] -keywords: [] -action: - aliases: [ge] - related: - - functions/compare/Eq - - functions/compare/Gt - - functions/compare/Le - - functions/compare/Lt - - functions/compare/Ne - returnType: bool - signatures: ['compare.Ge ARG1 ARG2 [ARG...]'] -aliases: [/functions/ge] ---- - -```go-html-template -{{ ge 1 1 }} → true -{{ ge 1 2 }} → false -{{ ge 2 1 }} → true - -{{ ge 1 1 1 }} → true -{{ ge 1 1 2 }} → false -{{ ge 1 2 1 }} → false -{{ ge 1 2 2 }} → false - -{{ ge 2 1 1 }} → true -{{ ge 2 1 2 }} → true -{{ ge 2 2 1 }} → true -``` diff --git a/docs/content/en/functions/compare/Gt.md b/docs/content/en/functions/compare/Gt.md deleted file mode 100644 index 0af289ce2..000000000 --- a/docs/content/en/functions/compare/Gt.md +++ /dev/null @@ -1,32 +0,0 @@ ---- -title: compare.Gt -description: Returns the boolean truth of arg1 > arg2 && arg1 > arg3. -categories: [] -keywords: [] -action: - aliases: [gt] - related: - - functions/compare/Eq - - functions/compare/Ge - - functions/compare/Le - - functions/compare/Lt - - functions/compare/Ne - returnType: bool - signatures: ['compare.Gt ARG1 ARG2 [ARG...]'] -aliases: [/functions/gt] ---- - -```go-html-template -{{ gt 1 1 }} → false -{{ gt 1 2 }} → false -{{ gt 2 1 }} → true - -{{ gt 1 1 1 }} → false -{{ gt 1 1 2 }} → false -{{ gt 1 2 1 }} → false -{{ gt 1 2 2 }} → false - -{{ gt 2 1 1 }} → true -{{ gt 2 1 2 }} → false -{{ gt 2 2 1 }} → false -``` diff --git a/docs/content/en/functions/compare/Le.md b/docs/content/en/functions/compare/Le.md deleted file mode 100644 index 319d376f6..000000000 --- a/docs/content/en/functions/compare/Le.md +++ /dev/null @@ -1,32 +0,0 @@ ---- -title: compare.Le -description: Returns the boolean truth of arg1 <= arg2 && arg1 <= arg3. -categories: [] -keywords: [] -action: - aliases: [le] - related: - - functions/compare/Eq - - functions/compare/Ge - - functions/compare/Gt - - functions/compare/Lt - - functions/compare/Ne - returnType: bool - signatures: ['compare.Le ARG1 ARG2 [ARG...]'] -aliases: [/functions/le] ---- - -```go-html-template -{{ le 1 1 }} → true -{{ le 1 2 }} → true -{{ le 2 1 }} → false - -{{ le 1 1 1 }} → true -{{ le 1 1 2 }} → true -{{ le 1 2 1 }} → true -{{ le 1 2 2 }} → true - -{{ le 2 1 1 }} → false -{{ le 2 1 2 }} → false -{{ le 2 2 1 }} → false -``` diff --git a/docs/content/en/functions/compare/Lt.md b/docs/content/en/functions/compare/Lt.md deleted file mode 100644 index 3fe8f1d2c..000000000 --- a/docs/content/en/functions/compare/Lt.md +++ /dev/null @@ -1,32 +0,0 @@ ---- -title: compare.Lt -description: Returns the boolean truth of arg1 < arg2 && arg1 < arg3. -categories: [] -keywords: [] -action: - aliases: [lt] - related: - - functions/compare/Eq - - functions/compare/Ge - - functions/compare/Gt - - functions/compare/Le - - functions/compare/Ne - returnType: bool - signatures: ['compare.Lt ARG1 ARG2 [ARG...]'] -aliases: [/functions/lt] ---- - -```go-html-template -{{ lt 1 1 }} → false -{{ lt 1 2 }} → true -{{ lt 2 1 }} → false - -{{ lt 1 1 1 }} → false -{{ lt 1 1 2 }} → false -{{ lt 1 2 1 }} → false -{{ lt 1 2 2 }} → true - -{{ lt 2 1 1 }} → false -{{ lt 2 1 2 }} → false -{{ lt 2 2 1 }} → false -``` diff --git a/docs/content/en/functions/compare/Ne.md b/docs/content/en/functions/compare/Ne.md deleted file mode 100644 index 2d9f826fc..000000000 --- a/docs/content/en/functions/compare/Ne.md +++ /dev/null @@ -1,27 +0,0 @@ ---- -title: compare.Ne -description: Returns the boolean truth of arg1 != arg2 && arg1 != arg3. -categories: [] -keywords: [] -action: - aliases: [ne] - related: - - functions/compare/Eq - - functions/compare/Ge - - functions/compare/Gt - - functions/compare/Le - - functions/compare/Lt - returnType: bool - signatures: ['compare.Ne ARG1 ARG2 [ARG...]'] -aliases: [/functions/ne] ---- - -```go-html-template -{{ ne 1 1 }} → false -{{ ne 1 2 }} → true - -{{ ne 1 1 1 }} → false -{{ ne 1 1 2 }} → false -{{ ne 1 2 1 }} → false -{{ ne 1 2 2 }} → true -``` diff --git a/docs/content/en/functions/compare/_index.md b/docs/content/en/functions/compare/_index.md deleted file mode 100644 index a9b3a7b27..000000000 --- a/docs/content/en/functions/compare/_index.md +++ /dev/null @@ -1,12 +0,0 @@ ---- -title: Compare functions -linkTitle: compare -description: Template functions to compare two or more values. -categories: [] -keywords: [] -menu: - docs: - parent: functions ---- - -Use these functions to compare two or more values. |