Skip to content
This repository has been archived by the owner on Mar 2, 2022. It is now read-only.

mesopelagique/NullCoaliescing

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

language language code-size discord

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 if

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