Unary map

The built-in map operator in the compiler allows for performing group operations on collection elements for various input streams. In this process, the user can define any number of custom closures and pass them as parameters to the map operator.

For example, by having a collection called ratios as the input, where the elements are expressed as 64-bit decimal numbers with fixed-point representation u64s, the user can transform them into a collection of percentages as the output. To achieve this, the user can define the closure as_pct and utilize it together with the map operator as follows:

let closure as_pct = (ratio: u64s) => ratio * 100
collection percentages = @input("COLLECTION_RATIONS")
.map(as_pct)

Additionally, the map operator can be defined within a new custom operator and used in operator chains without directly invoking the map operator itself. This new custom operator can be defined in a lower-level differential interface, where the declarations for input and output must be present, along with the logic for transforming data streams. The data stream transformation logic within the custom operator's body is described in the same way as in the external part of the program, i.e., as a sequence of operators. Conceptually, this can be seen as a kind of "sub-dataflow." In our example, the operator map is used to describe the operator's functionality for converting ratios to percentages:

operator to_pct<T> {
    input ratios: T
    output ratios
        .map(ratio => ratio * 100)
}
collection percentages = @input("COLLECTION_RATIONS")
.to_pct()

Last updated