Language functions
append
Arguments: [list: Nullable[List[Nullable[Anything]]], element: Nullable[Anything]]
Returns: List[Nullable[Anything]]
Append an element to a list.
concat
Arguments: [lhs: Nullable[List[Nullable[Anything]]], rhs: Nullable[List[Nullable[Anything]]]]
Returns: List[Nullable[Anything]]
Concatenate two lists to create a new list.
map
Arguments: [iterable: List[Nullable[Anything]], foreach: λ(list_element)]
Returns: List[Nullable[Anything]]
Apply an expression to each element in a list to produce a new list. Serves the same purpose in RiskScape as a for loop or a list comprehension.
For convenience, the iterable argument does not have to be a list type. You can pass map() a single item and the foreach lambda expression will be applied to the first argument directly. E.g. map(1, foreach: (x) -> x + 1) will simply return 2.
Treating both lists and single items as iterable makes pipeline code reusable for a variety of different modelling situations. For example, sampling the hazard-layer can result in either a single hazard intensity value or a list of values, depending on the function used.
filter
Arguments: [list: List[Nullable[Anything]], test: λ(list_element)]
Returns: List[Nullable[Anything]]
Filters the given list, returning a new list that contains only those elements that evaluate to true for the given test expression, e.g. filter([1,2,3], i -> i >= 2) returns [2, 3].
zip
Arguments: [lhs: List[Nullable[Anything]], rhs: List[Nullable[Anything]], lambda: λ(lhs_element,rhs_element)]
Returns: List[Nullable[Anything]]
Produces a new list by calling lamba with the nth elements from each input list, until the shortest input list is exhausted. For example the lamba expression (l1, l2) -> l1 + l2 would result in a list containing the sum of nth elements of each input list.
length
Arguments: [list: List[Nullable[Anything]]]
Returns: Integer
Returns the number of items in the list.
range
Arguments: [start: Integer, stop: Integer]
Returns: List[Integer]
Returns a list of integers that increase in value from start (inclusive) to stop (exclusive).
aggregate_struct
Arguments: [items: List[Nullable[Anything]], aggregation: Anything]
Returns: Nullable[Anything]
Aggregate function for applying aggregate functions to one of more members of a struct, e.g. group(struct_aggregate(loss, {max_damage: v -> max(v.damage)}), by: region) will apply max aggregation to the damage attribute of the loss type. Can also be used in a normal expression to aggregate values from tuples in a list.
null_of
Arguments: [typedef: Text]
Returns: Nullable[Anything]
Advanced function, useful for testing scenarios, for setting a null value of a specific type. For example, null_of('text') returns an expression that always evaluates to null but is still typed as text.
assert_not_null
Arguments: [value: Nullable[Anything], options: {message=>Text}]
Returns: Anything
Removes the nullable type from the given value, stopping pipeline execution if the value is found to be null.
The options may be used to customize the error message should a null value be found.
assert
Arguments: [condition: Bool, message: Text]
Returns: Nothing
Assert that condition is true otherwise a function exception, containing message, is raised to terminate model execution.
Useful to terminate long running models if invalid conditions are encountered.
warning
Arguments: [when: Bool, message: Text]
Returns: Nullable[Text]
Outputs a warning containing message if the when condition is true. The message is also returned, to help identify the data record(s) that generated the warning. If the when condition is false, null is returned and nothing is output.
merge
Arguments: [original: Anything, replace: Anything]
Returns: {}
Merge two structs to produce a new struct. Members of replace take precedence over the original. This method is not recursive - that is, any nested structs that share the same attribute name will not be merged, one will win and the other will be replaced completely.
call
Arguments: [scope: {}, lambda: λ()]
Returns: Anything
Internal/Expert function for applying an expression to a specific scope, excluding any outer scope, contrary to how most RiskScape functions work. Useful for testing/debugging scenarios.
to_list
Arguments: [value: Anything]
Returns: List[Anything]
Aggregate function for combining all grouped elements in to a list.
Use with caution on large datasets, as this can lead to slow performance and memory issues.
Can also be used in a normal expressions to turn relational data into a list, e.g. to_list(bookmark('input_data.csv'))