Coder Social home page Coder Social logo

mesopelagique / nullcoaliescing Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 1.0 38 KB

Null Coaliescing method using 4D

Home Page: https://mesopelagique.github.io/NullCoaliescing

License: MIT License

Roff 0.82% 4D 99.18%
4d 4dm 4d-component nvl coalesce

nullcoaliescing's Introduction

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

nullcoaliescing's People

Contributors

e-marchand avatar mesopelagique avatar phimage avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Forkers

ayoubserti

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.