# 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. ## `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. ## `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'))` ## `switch` Arguments: `[on: Anything, default: Anything, cases: List[{in=>List[Nullable[Anything]], return=>Anything}]]` Returns: `Anything` Returns a result based on the `on` value. The given cases are searched for one that contains the `on` value in the `in` list. If the value is matched then `return` is returned else searching continues. The `default` value is returned if there are no matches. Note that the `cases` argument must be constant. E.g `switch(on: 'bicycle', default: 'unknown', cases: [{in: ['bicycle', 'motorbike'], return: '2'},{in: ['car'], return: '4'}])` will return '2'. ## `remove_attr` Arguments: `[original: Anything, remove: Anything]` Returns: `{}` Returns a copy of `original` with the attribute specified by `remove` removed. `remove` can be either a string or a struct containing the attributes to be removed. For example: `remove_attr(exposure, 'geom')` returns a new struct with all the members of exposure except for `geom`, while `remove_attr(exposure, {exposure.geom, exposure.area})` removes both the `geom` and `area` attributes.