-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs/howto: validate an integer value's parity
This adds a Commented Cue guide demonstrating how to validate an integer value's parity. Examples are provided for the 8 different validation outcomes, based on the following matrix: - odd/even - positive/negative - valid/invalid For cue-lang/docs-and-content#97 Preview-Path: /docs/howto/validate-integer-value-parity/ Change-Id: Ibc7a31dcbbb13a8d155f30731c961691e47d79ed Signed-off-by: Noam Dolovich <noam.tzvi.dolovich@gmail.com> Reviewed-on: https://review.gerrithub.io/c/cue-lang/cuelang.org/+/1177968 Reviewed-by: Paul Jolly <paul@myitcv.io> Reviewed-by: Jonathan Matthews <github@hello.jonathanmatthews.com> TryBot-Result: CUEcueckoo <cueckoo@gmail.com>
- Loading branch information
1 parent
947e3f1
commit e57cd0e
Showing
7 changed files
with
141 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--- | ||
displayName: "Noam Dolovich" | ||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package site | ||
|
||
content: authors: noamtd: page: _ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
--- | ||
title: Validating an integer value's parity | ||
tags: | ||
- commented cue | ||
- validation | ||
authors: | ||
- noamtd | ||
toc_hide: true | ||
--- | ||
|
||
This [Commented CUE]({{< relref "docs/howto#commented-cue-guides" >}}) | ||
demonstrates how to validate an integer value's parity. | ||
|
||
Two schemas `#Odd` and `#Even` are presented that validate an integer is either odd or even respectively. | ||
|
||
{{{with code "en" "cc"}}} | ||
exec cue eval -ic | ||
cmp stdout out | ||
-- file.cue -- | ||
package example | ||
|
||
#Even: num={2 * (div(num, 2))} | ||
#Odd: num={1 + 2*(div(num, 2))} | ||
|
||
valid: { | ||
"-27": -27 & #Odd | ||
"-22": -22 & #Even | ||
"42": 42 & #Even | ||
"47": 47 & #Odd | ||
} | ||
|
||
invalid: { | ||
"-37": -37 & #Even | ||
"-32": -32 & #Odd | ||
"52": 52 & #Odd | ||
"57": 57 & #Even | ||
} | ||
-- out -- | ||
valid: { | ||
"-27": -27 | ||
"-22": -22 | ||
"42": 42 | ||
"47": 47 | ||
} | ||
invalid: { | ||
"-37": _|_ // invalid."-37": conflicting values -38 and -37 | ||
"-32": _|_ // invalid."-32": conflicting values -31 and -32 | ||
"52": _|_ // invalid."52": conflicting values 53 and 52 | ||
"57": _|_ // invalid."57": conflicting values 56 and 57 | ||
} | ||
{{{end}}} | ||
|
||
## Related content | ||
|
||
* {{< linkto/related/howto "use-the-built-in-functions-div-mod-quo-rem" >}} |
18 changes: 18 additions & 0 deletions
18
content/docs/howto/validate-integer-value-parity/gen_cache.cue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package site | ||
{ | ||
content: { | ||
docs: { | ||
howto: { | ||
"validate-integer-value-parity": { | ||
page: { | ||
cache: { | ||
code: { | ||
cc: "vf+j3IRvnHFecRWPM2a/7OODOwIDnMF6Rv3dTjzKZns=" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package site | ||
|
||
content: docs: howto: "validate-integer-value-parity": page: _ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--- | ||
displayName: "Noam Dolovich" | ||
--- |
56 changes: 56 additions & 0 deletions
56
hugo/content/en/docs/howto/validate-integer-value-parity/index.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
--- | ||
title: Validating an integer value's parity | ||
tags: | ||
- commented cue | ||
- validation | ||
authors: | ||
- noamtd | ||
toc_hide: true | ||
--- | ||
|
||
This [Commented CUE]({{< relref "docs/howto#commented-cue-guides" >}}) | ||
demonstrates how to validate an integer value's parity. | ||
|
||
Two schemas `#Odd` and `#Even` are presented that validate an integer is either odd or even respectively. | ||
|
||
{{< code-tabs >}} | ||
{{< code-tab name="file.cue" language="cue" area="top-left" >}} | ||
package example | ||
|
||
#Even: num={2 * (div(num, 2))} | ||
#Odd: num={1 + 2*(div(num, 2))} | ||
|
||
valid: { | ||
"-27": -27 & #Odd | ||
"-22": -22 & #Even | ||
"42": 42 & #Even | ||
"47": 47 & #Odd | ||
} | ||
|
||
invalid: { | ||
"-37": -37 & #Even | ||
"-32": -32 & #Odd | ||
"52": 52 & #Odd | ||
"57": 57 & #Even | ||
} | ||
{{< /code-tab >}} | ||
{{< code-tab name="TERMINAL" language="" area="top-right" type="terminal" codetocopy="Y3VlIGV2YWwgLWlj" >}} | ||
$ cue eval -ic | ||
valid: { | ||
"-27": -27 | ||
"-22": -22 | ||
"42": 42 | ||
"47": 47 | ||
} | ||
invalid: { | ||
"-37": _|_ // invalid."-37": conflicting values -38 and -37 | ||
"-32": _|_ // invalid."-32": conflicting values -31 and -32 | ||
"52": _|_ // invalid."52": conflicting values 53 and 52 | ||
"57": _|_ // invalid."57": conflicting values 56 and 57 | ||
} | ||
{{< /code-tab >}} | ||
{{< /code-tabs >}} | ||
|
||
## Related content | ||
|
||
* {{< linkto/related/howto "use-the-built-in-functions-div-mod-quo-rem" >}} |