Truthy
Truthy operator <<<&>>> is quite useful when the pipeline needs to continue only if the current value is considered <<<truthy>>>.
This operator is a unary operator meaning it won't take any operand.
The following values are considered <<<truthy>>>:
- All numbers except <<<0>>>, <<<0.0>>>.
- A string value if it is not empty <<<"">>>.
- A Buffer value when it is not empty <<<0x>>>. Buffer values of <<<0x0>>>, <<<0x00>>>, etc. are considered truthy.
Let's see a simple example of this operator,
1 & "will pass the vibration through" ?
0 & "will never vibrate" ?
If the incoming value is a gate of multiple values, the <<<truthy>>> logic is dependent on the type of the gate. An <<<AND>>> gate will be considered <<<truthy>>> if all its vibrations are <<<truthy>>>. This is following the definition of <<<AND>>> logic. As we saw before, <<<AND>>> gate is vibrating when all slots are available and vibrated. Using <<<&>>> you can have another layer of check.
For example,
(1, "Hello", 0.1) & // ✅
(0, "Hello", 1.0) & // ⛔️
(1, "", 0x) & // ⛔️
(1, "Hello", 0.0) & // ⛔️
(1, "Hello", (1, "")) & // ⛔️
An <<<OR>>> gate is considered <<<truthy>>> if at least one of its vibrations is considered <<<truthy>>>. This behavior is quite aligned with the behavior of an <<<OR>>> gate.
Not Truthy
<<<!&>>> operator behaves in the exact opposite way of <<<&>>> and will pass the vibration through only if it is considered a <<<Falsy>>> vibration. For example now,
1 !& "Will not pass through"
0 !& "Value 0 passes through"
As we always insist, simorg is built upon data. So any interaction should be data-driven. So a classical <<<else>>> branch no longer exists as this is not completely data-driven. Instead, all the possible pathways should explicitly be available to data.
"" $userInput
userInput & // will pass through
userInput !& "Invalid Empty Value Received!" ?
In the next chapter we will get familiar with <<<wrapper>>> shells, helping us with more advanced control flows.