Built-in Functions
Add
Adds the two arguments together
Usage:
first = 1 + 1 == 2;
second = 123 + 321 == 444;
third = -321 + 321 == 0;
All
Checks if all arguments are truthy
Usage:
first = all([1, true, [1,2,3], {"test": true}]);
second = all([1, false, [1,2,3], {"test": true}]) == false;
And
If the first argument is truthy returns the second argument, otherwise returns the first argument
Usage:
first = true and true;
second = 1 and true;
third = [1,2,3] and true;
fourth = 0 and 1234 == 0;
Any
Checks if any arguments are truthy
Usage:
first = any([1, false, [1,2,3], {"test": true}]);
second = any([0.0, true, [], {}]);
third = any([0.0, false, [], {}]) == false;
Assert
Raises an error with the given message if the first argument is not truthy
Usage:
one = assert(true == true);
two = assert([1,2,3]) == [1,2,3];
# with an optional error message
three = assert(1, "not truthy") == 1;
four = try(assert(1 == 0, "panic"), "default") == "default";
Call
Calls the function with given arguments
Usage:
my_function = {x => x + 25};
one = my_function.(5) == 30;
# the same as:
two = call(my_function, 5) == 30;
one and two
Concat
Combines two or more lists into one
Usage:
first = concat([1,2], [3,4], [5,6]) == [1,2,3,4,5,6];
second = concat("test", "-", "test") == "test-test";
Contains
Checks if the seconds argument is in the first argument
Usage:
first = contains("testing", "test");
second = contains([1,2,3,4], 3);
Cos
Calculates the cosine of the number
Usage:
first = cos(0) == 1;
Div
Divides the second argument from the first argument
Usage:
first = 1 / 5 == 0.2;
second = 50 / 50 == 1;
third = 150 / 6 == 25;
Equal
Compares if the two arguments are equal
Usage:
first = 1 == 1;
second = [1,2,3] == [1,2,3];
third = {"test": true} == {"test": true};
Error
Raises an error with the given message
Usage:
# an error with "something went wrong" will be catched and returns "default"
one = try(error("something went wrong"), "default") == "default";
Format
Formats the arguments into the template, only positional arguments are supported.
Usage:
one = format("{} + {} = {}", 1, 1, 2) == "1 + 1 = 2";
two = format("{2} - {1} = {0}", 5, 8, 13) == "13 - 8 = 5";
three = format("{}{}", "abc", "def") == "abcdef";
one and two and three
Get
Gets the value from a list or a map
Usage:
first = get([1, 2, 3], 1) == 2;
// throws error:
// get([1, 2, 3], -1.23) != 2;
second = get([1, 2, 3], 1.5 - 0.5) == 2;
third = get({"test": 12, "another": -1}, "test") == 12;
// throws error:
// get({"test": 1}, "another")
Greater
Compares if left is greater than right
Usage:
first = 2 > 1;
Help
Prints help message
Usage:
// prints general help
help();
// prints help for specific function
help(contains);
// print all the functions
help(functions);
If
If the first argument is truthy returns the second argument, otherwise returns the third argument
Usage:
first = if(1 == 1, "success", "failed") == "success";
one = "1";
two = "2";
some_test = e != pi;
second = if(some_test, one, two) == one;
// if function can also take a function
third = if(1 == 1, {=>
1 + 2
}, {=>
"error"
}) == 3;
Join
Combine the first argument into a string with the second argument as is seperator
Usage:
first = join(["1", "2", "3"], ", ") == "1, 2, 3";
second = join(["test", "testing", "test"], "-") == "test-testing-test";
Length
Returns the length of map of list
Usage:
first = length(["1", "2", "3"]) == 3;
second = length({"test": 1, "another": 3}) == 2;
third = length(range(15)) == 15;
Lesser
Compares if left is less than right
Usage:
first = 1 < 2;
Lower
Converts input to lowercase
Usage:
first = lower("TESTING") == "testing";
Mul
Multiplies the two arguments together
Usage:
first = 1 * 1 == 1;
second = 150 * 0 == 0;
third = -5 * -5 == 25;
Not equal
Compares if the two arguments are not equal
Usage:
first = 1 != 2;
second = [1,2,3] != [3,2,1];
third = {"test": true} != {"test": false};
Now
Returns the unix timestamp of the current time
Usage:
now();
Or
If the first argument is truthy returns the first argument, otherwise returns the second argument
Usage:
first = false or true;
second = 0.0 or true;
third = [] or true;
Pow
Raises the first argument to the second argument
Usage:
first = 1 ** 1 == 1;
second = 2 ^ 3 == 8;
third = 16 ** 0.5 == 4;
Prints value
Usage:
// prints the item to configured logger
one = print({"test": 1}) == {"test": 1};
one
Product
Calculates the product of the arguments
Usage:
first = product(1,2,3,4,5) == 120;
second = product([1,2,3,4,5]) == 120;
Push
Push value to the list
Usage:
first = push([1, 2, 3], 1) == [1,2,3,1];
second = push([1, 2, 3], [1, 2, 3]) == [1,2,3,[1,2,3]];
Put
Put third argument into the map or list under the second argument
Usage:
first = put({}, "test", 123) == {"test": 123};
// overwrites existing key
second = put({"test": 23}, "test", 5) == {"test": 5};
third = put({"test": 23}, "test", put({"nested": 23}, "nested", 5)) == {"test": {"nested": 5}};
// put replaces the value at the index
four = put([1, 2, 3], 2, 15) == [1, 2, 15];
Random
Generate a random number. Defaults to a number between 0 and 1, but the range can be set as argument
Usage:
// random() returns a random number between 0 and 1
first = random() != random();
second = random(-1, 1) != random(2, 5);
third = random(-5) != random(5);
Range
Generate a list
Usage:
// generates a list till the given argument
first = range(3) == [0,1,2];
// generates a list from to the given arguments
second = range(1, 4) == [1,2,3];
// generate a list from to the given arguments with an additional step argument
third = range(0, 15, 5) == [0, 5, 10];
four = range(0, 16, 5) == [0, 5, 10, 15];
// the last argument can also be a function that returns the next value
// this will generate the squares of the values in the range
five = range(0, 4, {x => x*x}) == [0, 1, 4, 9];
// the last argument is just a function so it can also be used with variables
filler = 10;
six = range(0, 4, {=> filler}) == [10, 10, 10, 10];
multiplier = {multiply => {number => multiply*number}};
times_three = multiplier.(3);
times_five = multiplier.(5);
seven = range(0, 4, times_three) == [0, 3, 6, 9];
eight = range(0, 4, times_five) == [0, 5, 10, 15];
Reduce
Reduce a list to a single value
Usage:
// sum functionality
one = reduce([1,2,3,4], 0, {acc, x => acc + x}) == 10;
// map like functionality
two = reduce([1,2], [], {acc, x => push(acc, x*3)}) == [3,6];
// generate a map. This example generates a map with odd numbers
three = reduce([1,2,3,4], {}, {acc, item =>
put(acc, format("key-{}", item), item * 2 + 1)
}) == {"key-1": 3, "key-2": 5, "key-3": 7, "key-4": 9};
Remove
Removes index from the list or key from the map
Usage:
// for lists
first = remove([1, 2, 3], 1) == [1, 3];
second = remove([1, 2, 3], -1) == [1, 2];
// for maps
third = remove({"test": 1}, "test") == {};
four = remove({"test": 1}, "another") == {"test": 1};
five = remove({"test": 1, "another": 123}, "another") == {"test": 1};
Shuffle
Shuffles the given list
Usage:
shuffle([1,2,3,4]);
Sin
Calculates the sine of the number
Usage:
first = sin(0) == 0;
Sub
Subtracts the second argument from the first argument
Usage:
first = 1 - 1 == 0;
second = 421 - 321 == 100;
third = -123 - 321 == -444;
Sum
Sums up the arguments
Usage:
first = sum(1,2,3,4,5) == 15;
second = sum([1,2,3,4,5]) == 15;
Tan
Calculates the tangent of the number
Usage:
first = tan(0) == 0;
Trim
Removes the characters at the start and end of the first argument, second argument is an optional argument that contains the character to remove, defaults to ' '
Usage:
first = trim(" test ") == "test";
second = trim("__Testing_Test__", "_") == "Testing_Test";
third = trim("A sentence.\n\n\n\n\n", "\n") == "A sentence.";
Try
Tries the first argument, if that fails returns the second argument
Usage:
// will just return the get function
first = try(get({"test": 10}, "test"), 123) == 10;
// get function will raise because "test" is not found
second = try(get({}, "test"), 123) == 123;
map = {"test": 15};
invalid_key = 1;
third = try(put(map, invalid_key, 123), map) == map;
Type
Returns the type of the argument
Usage:
one = type(1.0) == "number";
two = type([]) == "list";
three = type({}) == "map";
four = type("test") == "string";
five = type({=> x}) == "function";
six = type(true) == "boolean";
seven = type(null) == "null";
Upper
Converts input to uppercase
Usage:
first = upper("testing") == "TESTING";