Null coalescing using 4D ?:)
ARCHIVED: now 4D support short circuit with JS style https://blog.4d.com/4d-language-improvements/
Defined a default value if NULL
C_VARIANT($value;$Obj;$NullObject)
$Obj:=New object()
$value:=NVL($NullObject;$Obj) // $value eq. $Obj (same as Choose($NullObject=Null;$Obj;$NullObject) )C_VARIANT($value;$Obj)
$Obj:=New object()
For each ($value;NVL ($Obj.collection;New collection))
// do something
End for each
Same as NVL but with more than one possible NULL element.
C_VARIANT($value;$Obj)
$Obj:=New object()
For each ($value;COALESCE ($Obj.collection1;$Obj.collection3;New collection))
// do something
End for each
Checking if NULL before applying any formula.
If (NVF ($collection;Formula($1.length>2)))
For each ($element;$collection)
End for each
End ifGet the first defined value from an object.
$obj:=New object("a"; New object("b";"d");"dot.dot"; 5)
$value:=PATH_COALESCE($obj;New collection("a.z";"d";"a.b";"dot.dot");$defaultValue)
// Will return "d" because "a.b" is the first 'correct' pathAlternative to Null Coalescing, in case you want to provide the default value for the data type,
you can use Bool, Int, String or for any data type GetValueOrDefault
If(Bool($Obj.success))
// do something d
End ifFor each ($value;GetValueOrDefault($Obj.collection1))
// do something
End for each