List Formula
Introduction
Sapper supports a variety of list formulas. Those are mentioned in this section.
Formulas
FIRST
Description | Returns the first item in a list. It can also be used to return the first n items in a list. In this case, the output will be formatted as a list. |
Syntax | Expression: FIRST(List l, int index) Return Type: List |
Example | Expression: FIRST('1,2,3,4,5,6,7',5) Result: [1, 2, 3, 4, 5] |
LAST
Description | Returns the last item in a list. It can also be used to return the last n items in a list. In this case, the output will be formatted as a list. |
Syntax | Expression: LAST(List l, int index) Return Type: List |
Example | Expression: LAST('1,2,3,4,5,6,7',3) Result: [5, 6, 7] |
INDEX
Description | Returns the index of the first item matching the given value (it works for a list of primitive type) |
Syntax | Expression: INDEX(List l, int index) Return Type: List |
Example | Expression: INDEX({1, 2, 3, 4}, 3) Result: 2 |
UNIQ
Description | Returns a list containing unique items i.e. remove duplicate items. |
Syntax | Expression: UNIQ(List l) Return Type: List |
Example | Expression: UNIQ('1,2,2,2,3,4,4') Result: [1, 2, 3, 4] |
LENGTH
Description | Returns the number of elements in self. Returns 0 if the list is empty. |
Syntax | Expression: LENGTH(List l) Return Type: List |
Example | Expression: LENGTH({1, 2, 3,5,6,7,8}) , LENGTH({'m','g','f','q'}) Result: 7,4 |
BLANK
Description | Checks the input string and returns true if it is an empty string or if it is null. |
Syntax | Expression: BLANK(Object o) Return Type: Boolean |
Example | Expression: BLANK('Hello') Result: false |
INCLUDE
Description | Checks if the string contains a specific substring. Returns true if it does. |
Syntax | Expression: INCLUDE(String s, String subString) Return Type: Boolean |
Example | Expression: INCLUDE('hello','he') Result: true |
PRESENT
Description | Check the input and if there is a value present, it will return true. If the input is null, an empty string, or an empty list, the function will return false. |
Syntax | Expression: PRESENT(Object o) Return Type: Boolean |
Example | Expression: PRESENT([1, 2]) Result: TRUE |
PRESENCE
Description | Returns the data if it exists, returns null if it does not. |
Syntax | Expression: PRESENCE(Object o) Return Type: Object/Null |
Example | Expression: PRESENCE('Hello') Result: Hello |
KEYS
Description | Returns an array of keys from the input hash of primitive type. |
Syntax | Expression: KEYS(Map m) Return Type: List |
Example | Expression: KEYS({a:1, b:2, c:3}) Result: [a,b,c] |