View on GitHub

NullCoaliescing

Null Coaliescing method using 4D

language language code-size discord

Null coalescing using 4D ?:)

NVL

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 

COALESCE

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 

NVF

Checking if NULL before applying any formula.

If (NVF ($collection;Formula($1.length>2)))
	For each ($element;$collection)

	End for each
End if

PATH_COALESCE

Get 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' path

GetValueOrDefault

Alternative 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 if
For each ($value;GetValueOrDefault($Obj.collection1))
	// do something
End for each

Elvis


mesopelagique