Some examples of complex expressions - Gnorion/BizVR GitHub Wiki
NOTE: all the examples use literal value but in any place you see a literal value it may also be an attribute name or any expression (that returns an appropriate data type)
So expressions can be nested arbitrarily deep (not recommended)
Expression | Result |
---|---|
IF THEN ELSE | |
if 20 > 0 then "YES" else "NO" | ➔ "YES" |
if (20 - (10 * 2)) > 0 then "YES" else "NO" | ➔ "NO" |
if (2 ** 3) = 8 then "YES" else "NO" | ➔ "YES" |
if (4 / 2) != 2 then "YES" else "NO" | ➔ "NO" |
ITERATION | |
for i in [1, 2, 3] return i * i | ➔ [1, 4, 9] |
for i in 1..3 return i * i | ➔ [1, 4, 9] |
for i in [1,2,3], j in [1,2,3] return i*j | ➔ [1, 2, 3, 2, 4, 6, 3, 6, 9] |
for x in @"2021-01-01"..@"2021-01-03" return x + 1 | ➔ [date("2021-01-02"), date("2021-01-03"), date("2021-01-04")] |
EXISTS | |
some i in [1, 2, 3] satisfies i > 2 | ➔ true |
some i in [1, 2, 3] satisfies i > 4 | ➔ false |
FOR ALL | |
every i in [1, 2, 3] satisfies i > 1 | ➔ false |
every i in [1, 2, 3] satisfies i > 0 | ➔ true |
IN | |
1 in [1..10] | ➔ true |
1 in (1..10] | ➔ false |
10 in [1..10] | ➔ true |
10 in [1..10) | ➔ false |
BOOLEAN | |
true and true | ➔ true |
true and false and null | ➔ false |
true and null and true | ➔ null |
true or false or null | ➔ true |
false or false | ➔ false |
false or null or false | ➔ null |
true or false and false | ➔ true |
(true or false) and false | ➔ false |
STRINGS | |
"some" + "string" | ➔ "somestring" |
"very" + "long" + "word" | ➔ "verylongword" |
substring( "testing",3 ) | ➔ "sting" |
substring( "testing",3,3 ) | ➔ "sti" |
substring( "testing", -2, 1 ) | ➔ "n" |
substring( "\U01F40Eab", 2 ) | ➔ "ab" |
string length( "tes" ) | ➔ 3 |
string length( "\U01F40Eab" ) | ➔ 3 |
upper case( "aBc4" ) | ➔ "ABC4" |
lower case( "aBc4" ) | ➔ "abc4" |
substring before( "testing", "ing" ) | ➔ "test" |
substring before( "testing", "xyz" ) | ➔ "" |
substring after( "testing", "test" ) | ➔ "ing" |
substring after( "", "a" ) | ➔ "" |
replace( "banana", "a", "o" ) | ➔ "bonono" |
replace( "abcd", "(ab) | (a)", "[1 |
contains( "testing", "to" ) | ➔ false |
starts with( "testing", "te" ) | ➔ true |
ends with( "testing", "g" ) | ➔ true |
matches( "teeesting", "^te*sting" ) | ➔ true |
split( "John Doe", "\s" ) | ➔ ["John", "Doe"] |
split( "a;b;c;;", ";" ) | ➔ ["a","b","c","",""] |
string join(["a","b","c"], "and") | ➔ "a_and_b_and_c" |
string join(["a","b","c"], "") | ➔ "abc" |
string join(["a","b","c"], null) | ➔ "abc" |
string join(["a"], "X") | ➔ "a" |
string join(["a",null,"c"], "X") | ➔ "aXc" |
string join([], "X") | ➔ "" |
string join(["a","b","c"]) | ➔ "abc" |
string join(["a",null,"c"]) | ➔ "ac" |
string join([], "X") | ➔ "" |
LISTS | |
list contains( [1,2,3], 2 ) | ➔ true |
list replace( [2, 4, 7, 8], 3, 6) | ➔ [2, 4, 6, 8] |
list replace ( [2, 4, 7, 8], function(item, newItem) item < newItem, 5) | ➔ [5, 5, 7, 8] |
count( [1,2,3] ) | ➔ 3 |
count( [] ) | ➔ 0 |
count( [1,[2,3]] ) | ➔ 2 |
MATH | |
min( [1,2,3] ) | ➔ 1 |
min( 1 ) | ➔ 1 |
min( [1] ) | ➔ 1 |
max( 1,2,3 ) | ➔ 3 |
max( [] ) | ➔ null |
sum( [1,2,3] ) | ➔ 6 |
sum( 1,2,3 ) | ➔ 6 |
sum( 1 ) | ➔ 1 |
sum( [] ) | ➔ null |
mean( [1,2,3] ) | ➔ 2 |
mean( 1,2,3 ) | ➔ 2 |
mean( 1 ) | ➔ 1 |
mean( [] ) | ➔ null |
all( [false,null,true] ) | ➔ false |
all( true ) | ➔ true |
all( [true] ) | ➔ true |
all( [] ) | ➔ true |
all( 0 ) | ➔ null |
any( [false,null,true] ) | ➔ true |
any( false ) | ➔ false |
any( [] ) | ➔ false |
any( 0 ) | ➔ null |
sublist( [4,5,6], 1, 2 ) | ➔ [4,5] |
append( [1], 2, 3 ) | ➔ [1,2,3] |
concatenate( [1,2],[3] ) | ➔ [1,2,3] |
insert before( [1,3],1,2 ) | ➔ [2,1,3] |
remove( [1,2,3], 2 ) | ➔ [1,3] |
reverse( [1,2,3] ) | ➔ [3,2,1] |
index of( [1,2,3,2],2 ) | ➔ [2,4] |
union( [1,2],[2,3] ) | ➔ [1,2,3] |
distinct values( [1,2,3,2,1] ) | ➔ [1,2,3] |
flatten( [1,2],[3, 4] ) | ➔ [1,2,3,4] |
product( [2, 3, 4] ) | ➔ 24 |
product( [] ) | ➔ null |
product( 2, 3, 4 ) | ➔ 24 |
median( 8, 2, 5, 3, 4 ) | ➔ 4 |
median( [6, 1, 2, 3] ) | ➔ 2.5 |
median( [ ] ) | ➔ null |
stddev( 2, 4, 7, 5 ) | ➔ 2.081665999466132735282297706979931 |
stddev( [47] ) | ➔ null |
stddev( 47 ) | ➔ null |
stddev( [ ] ) | ➔ null |
mode( 6, 3, 9, 6, 6 ) | ➔ [6] |
mode( [6, 1, 9, 6, 1] ) | ➔ [1, 6] |
mode( [ ] ) | ➔ [ ] |
decimal( 1/3, 2 ) | ➔ .33 |
decimal( 1.5, 0 ) | ➔ 2 |
decimal( 2.5, 0 ) | ➔ 2 |
decimal( 1.035, 2 ) | ➔ 1.04 |
decimal( 1.045, 2 ) | ➔ 1.04 |
decimal( 1.055, 2 ) | ➔ 1.06 |
decimal( 1.065, 2 ) | ➔ 1.06 |
floor( 1.5 ) | ➔ 1 |
floor( -1.56, 1 ) | ➔ -1.6 |
floor( -1.5 ) | ➔ -2 |
ceiling( 1.5 ) | ➔ 2 |
ceiling( -1.56, 1 ) | ➔ -1.5 |
ceiling( -1.5 ) | ➔ -1 |
round up( 5.5, 0 ) | ➔ 6 |
round up( -5.5, 0 ) | ➔ -6 |
round up( 1.121, 2 ) | ➔ 1.13 |
round up( -1.126, 2 ) | ➔ -1.13 |
round down( 5.5, 0 ) | ➔ 5 |
round down( -5.5, 0 ) | ➔ -5 |
round down( 1.121, 2 ) | ➔ 1.12 |
round down( -1.126, 2 ) | ➔ -1.12 |
round half up( 5.5, 0 ) | ➔ 6 |
round half up( -5.5, 0 ) | ➔ -6 |
round half up( 1.121, 2 ) | ➔ 1.12 |
round half up( -1.126, 2 ) | ➔ -1.13 |
round half down( 5.5, 0 ) | ➔ 5 |
round half down( -5.5, 0 ) | ➔ -5 |
round half down( 1.121, 2 ) | ➔ 1.12 |
round half down( -1.126, 2 ) | ➔ -1.13 |
abs( 10 ) | ➔ 10 |
abs( -10 ) | ➔ 10 |
abs( @"PT5H" ) | ➔ @"PT5H" |
abs( @"-PT5H" ) | ➔ @"PT5H" |
modulo( 12, 5 ) | ➔ 2 |
modulo( -12,5 ) | ➔ 3 |
modulo( 12,-5 ) | ➔ -3 |
modulo( -12,-5 ) | ➔ -2 |
modulo( 10.1, 4.5 ) | ➔ 1.1 |
modulo( -10.1, 4.5 ) | ➔ 3.4 |
modulo( 10.1, -4.5 ) | ➔ -3.4 |
modulo( -10.1, -4.5 ) | ➔ -1.1 |
sqrt( 16 ) | ➔ 4 |
decimal( log( 10 ), 2 ) | ➔ 2.30 |
decimal( exp( 5 ), 2 ) | ➔ 148.41 |
odd( 5 ) | ➔ true |
odd( 2 ) | ➔ false |
even( 5 ) | ➔ false |
even ( 2 ) | ➔ true |
not( true ) | ➔ false |
not( null ) | ➔ null |
is( date( "2012-12-25" ), time( "23:00:50" ) ) | ➔ false |
is( date( "2012-12-25" ), date( "2012-12-25" ) ) | ➔ true |
is( time( "23:00:50z" ), time( "23:00:50" ) ) | ➔ false |
is( time( "23:00:50z" ), time( "23:00:50+00:00" ) ) | ➔ true |
before( 1, 10 ) | ➔ true |
before( 10, 1 ) | ➔ false |
before( 1, [1..10] ) | ➔ false |
before( 1, (1..10] ) | ➔ true |
before( 1, [5..10] ) | ➔ true |
before( [1..10], 10 ) | ➔ false |
before( [1..10), 10 ) | ➔ true |
before( [1..10], 15 ) | ➔ true |
before( [1..10], [15..20] ) | ➔ true |
before( [1..10], [10..20] ) | ➔ false |
before( [1..10), [10..20] ) | ➔ true |
before( [1..10], (10..20] ) | ➔ true |
before( "@2020-01-01", ["@2021-01-01".."@2022-01-01"]) | ➔ true |
before( "@2024-01-01", ["@2021-01-01".."@2022-01-01"]) | ➔ false |
after( 10, 5 ) | ➔ true |
after( 5, 10 ) | ➔ false |
after( 12, [1..10] ) | ➔ true |
after( 10, [1..10) ) | ➔ true |
after( 10, [1..10] ) | ➔ false |
after( [11..20], 12 ) | ➔ false |
after( [11..20], 10 ) | ➔ true |
after( (11..20], 11 ) | ➔ true |
after( [11..20], 11 ) | ➔ false |
after( [11..20], [1..10] ) | ➔ true |
after( [1..10], [11..20] ) | ➔ false |
after( [11..20], [1..11) ) | ➔ true |
after( (11..20], [1..11] ) | ➔ true |
after( "@2020-01-01", ["@2021-01-01".."@2022-01-01"]) | ➔ false |
after( "@2024-01-01", ["@2021-01-01".."@2022-01-01"]) | ➔ true |
meets( [1..5], [5..10] ) | ➔ true |
meets( [1..5), [5..10] ) | ➔ false |
meets( [1..5], (5..10] ) | ➔ false |
meets( [1..5], [6..10] ) | ➔ false |
met by( [5..10], [1..5] ) | ➔ true |
met by( [5..10], [1..5) ) | ➔ false |
met by( (5..10], [1..5] ) | ➔ false |
met by( [6..10], [1..5] ) | ➔ false |
overlaps( [1..5], [3..8] ) | ➔ true |
overlaps( [3..8], [1..5] ) | ➔ true |
overlaps( [1..8], [3..5] ) | ➔ true |
overlaps( [3..5], [1..8] ) | ➔ true |
overlaps( [1..5], [6..8] ) | ➔ false |
overlaps( [6..8], [1..5] ) | ➔ false |
overlaps( [1..5], [5..8] ) | ➔ true |
overlaps( [1..5], (5..8] ) | ➔ false |
overlaps( [1..5), [5..8] ) | ➔ false |
overlaps( [1..5), (5..8] ) | ➔ false |
overlaps( [5..8], [1..5] ) | ➔ true |
overlaps( (5..8], [1..5] ) | ➔ false |
overlaps( [5..8], [1..5) ) | ➔ false |
overlaps( (5..8], [1..5) ) | ➔ false |
overlaps before( [1..5], [3..8] ) | ➔ true |
overlaps before( [1..5], [6..8] ) | ➔ false |
overlaps before( [1..5], [5..8] ) | ➔ true |
overlaps before( [1..5], (5..8] ) | ➔ false |
overlaps before( [1..5), [5..8] ) | ➔ false |
overlaps before( [1..5), (1..5] ) | ➔ true |
overlaps before( [1..5], (1..5] ) | ➔ true |
overlaps before( [1..5), [1..5] ) | ➔ false |
overlaps before( [1..5], [1..5] ) | ➔ false |
overlaps after( [3..8], [1..5] ) | ➔ true |
overlaps after( [6..8], [1..5] ) | ➔ false |
overlaps after( [5..8], [1..5] ) | ➔ true |
overlaps after( (5..8], [1..5] ) | ➔ false |
overlaps after( [5..8], [1..5) ) | ➔ false |
overlaps after( (1..5], [1..5) ) | ➔ true |
overlaps after( (1..5], [1..5] ) | ➔ true |
overlaps after( [1..5], [1..5) ) | ➔ false |
overlaps after( [1..5], [1..5] ) | ➔ false |
overlaps after( (1..5), [1..5] ) | ➔ false |
overlaps after( (1..5], [1..6] ) | ➔ false |
overlaps after( (1..5], (1..5] ) | ➔ false |
overlaps after( (1..5], [2..5] ) | ➔ false |
finishes( 10, [1..10] ) | ➔ true |
finishes( 10, [1..10) ) | ➔ false |
finishes( [5..10], [1..10] ) | ➔ true |
finishes( [5..10), [1..10] ) | ➔ false |
finishes( [5..10), [1..10) ) | ➔ true |
finishes( [1..10], [1..10] ) | ➔ true |
finishes( (1..10], [1..10] ) | ➔ true |
finished by( [1..10], 10 ) | ➔ true |
finished by( [1..10), 10 ) | ➔ false |
finished by( [1..10], [5..10] ) | ➔ true |
finished by( [1..10], [5..10) ) | ➔ false |
finished by( [1..10), [5..10) ) | ➔ true |
finished by( [1..10], [1..10] ) | ➔ true |
finished by( [1..10], (1..10] ) | ➔ true |
includes( [1..10], 5 ) | ➔ true |
includes( [1..10], 12 ) | ➔ false |
includes( [1..10], 1 ) | ➔ true |
includes( [1..10], 10 ) | ➔ true |
includes( (1..10], 1 ) | ➔ false |
includes( [1..10), 10 ) | ➔ false |
includes( [1..10], [4..6] ) | ➔ true |
includes( [1..10], [1..5] ) | ➔ true |
includes( (1..10], (1..5] ) | ➔ true |
includes( [1..10], (1..10) ) | ➔ true |
includes( [1..10), [5..10) ) | ➔ true |
includes( [1..10], [1..10) ) | ➔ true |
includes( [1..10], (1..10] ) | ➔ true |
includes( [1..10], [1..10] ) | ➔ true |
starts( 1, [1..10] ) | ➔ true |
starts( 1, (1..10] ) | ➔ false |
starts( 2, [1..10] ) | ➔ false |
starts( [1..5], [1..10] ) | ➔ true |
starts( (1..5], (1..10] ) | ➔ true |
starts( (1..5], [1..10] ) | ➔ false |
starts( [1..5], (1..10] ) | ➔ false |
starts( [1..10], [1..10] ) | ➔ true |
starts( [1..10), [1..10] ) | ➔ true |
starts( (1..10), (1..10) ) | ➔ true |
started by( [1..10], 1 ) | ➔ true |
started by( (1..10], 1 ) | ➔ false |
started by( [1..10], 2 ) | ➔ false |
started by( [1..10], [1..5] ) | ➔ true |
started by( (1..10], (1..5] ) | ➔ true |
started by( [1..10], (1..5] ) | ➔ false |
started by( (1..10], [1..5] ) | ➔ false |
started by( [1..10], [1..10] ) | ➔ true |
started by( [1..10], [1..10) ) | ➔ true |
started by( (1..10), (1..10) ) | ➔ true |
coincides( 5, 5 ) | ➔ true |
coincides( 3, 4 ) | ➔ false |
coincides( [1..5], [1..5] ) | ➔ true |
coincides( (1..5), [1..5] ) | ➔ false |
coincides( [1..5], [2..6] ) | ➔ false |
TEMPORAL | |
day of year( date(2019, 9, 17) ) | ➔ 260 |
day of week( date(2019, 9, 17) ) | ➔ "Tuesday" |
Month of year( date(2019, 9, 17) ) | ➔ "September" |
week of year( date(2019, 9, 17) ) | ➔ 38 |
week of year( date(2003, 12, 29) ) | ➔ 1 |
week of year( date(2004, 1, 4) ) | ➔ 1 |
week of year( date(2005, 1, 1) ) | ➔ 53 |
week of year( date(2005, 1, 3) ) | ➔ 1 |
week of year( date(2005, 1, 9) ) | ➔ 1 |
list | |
sort( list: [3,1,4,5,2], precedes: function(x,y) x < y ) | ➔ [1,2,3,4,5] |
get value( {key1 : "value1"}, "key1" ) | ➔ "value1" |
get value( {key1 : "value1"}, "unexistent-key" ) | ➔ null |
get entries( {key1 : "value1", key2 : "value2"} ) | ➔ [ { key : "key1", value : "value1" }, {key : "key2", value : "value2"} ] |
context([{key:"a", value:1}, {key:"b", value:2}]) | ➔ {a:1, b:2} |
context([{key:"a", value:1}, {key:"b", value:2, something: "else"}]) | ➔ {a:1, b:2} |
context([{key:"a", value:1}, {key:"b"}]) | ➔ null |
context put({x:1}, "y", 2) | ➔ {x:1, y:2} |
context put({x:1, y:0}, "y", 2) | ➔ {x:1, y:2} |
context put({x:1, y:0, z:0}, "y", 2) | ➔ {x:1, y:2, z:0} |
context put({x:1}, ["y"], 2) | ➔ context put({x:1}, "y", 2) |
context put({x:1}, ["y"], 2) | ➔ {x:1, y:2} |
context put({x:1, y: {a: 0} }, ["y", "a"], 2) | ➔ context put({x:1, y: {a: 0} }, "y", context put({a: 0}, ["a"], 2)) |
context put({x:1, y: {a: 0} }, ["y", "a"], 2) | ➔ {x:1, y: {a: 2} } |
context put({x:1, y: {a: 0} }, [], 2) | ➔ null |
context merge([{x:1}, {y:2}]) | ➔ {x:1, y:2} |
context merge([{x:1, y:0}, {y:2}]) | ➔ {x:1, y:2} |
date( "2012-12-25" ) - date( "2012-12-24" ) | ➔ duration( "P1D" ) |
date(date and time( "2012-12-25T11:00:00Z" )) | ➔ date( "2012-12-25" ) |
date( 2012, 12, 25 ) | ➔ date( "2012-12-25" ) |
date and time ( "2012-12-24T23:59:00" ) | ➔ date and time(date( "2012-12-24" ), time( "23:59:00" )) |
date and time( "2012-12-24T23:59:00" ) + duration( "PT1M" ) | ➔ date and time( "2012-12-25T00:00:00" ) |
time( "23:59:00z" ) + duration( "PT2M" ) | ➔ time( "00:01:00@Etc/UTC" ) |
time(date and time( "2012-12-25T11:00:00Z" )) | ➔ time( "11:00:00Z" ) |
time( "23:59:00z" ) | ➔ time(23, 59, 0, duration( "PT0H" )) |
number( "1 000,0", " ", "," ) | ➔ number( "1,000.0", ",", "." ) |
string( 1.1 ) | ➔ "1.1" |
string( null ) | ➔ null |
date and time( "2012-12-24T23:59:00" ) - date and time( "2012-12-22T03:45:00" ) | ➔ duration( "P2DT20H14M" ) |
duration( "P2Y2M" ) | ➔ duration( "P26M" ) |
years and months duration( date( "2011-12-22" ), date( "2013-08-24" ) ) | ➔ duration( "P1Y8M" ) |
now() | |
today() | |
invoke("http://namespace_of_model","my model name","my decision name", { a:1, b:2 }) |