Extension:ArrayFunctions/Essentials/Composing functions

Parser functions defined by ArrayFunctions are pure, meaning that arrays are not stored in a variable. Instead, the array is outputted by the parser function directly. This is in contrast to similar extensions like Arrays or Variables, which require users to assign names to values, which is not compatible with Parsoid.

The stateless nature of ArrayFunctions parser functions makes using it fundamentally different compared to the aforementioned extensions. Rather than imperatively modifying an array stored in a variable, users must rely on function composition to perform more complex operations. This is shown in the example below.

Arrays ArrayFunctions
{{#arraydefine: fruits | orange, banana, strawberry, apple }}
{{#arraysort: fruits | asc }}
{{#arrayprint: fruits }}
{{#af_print: 
    {{#af_sort: 
        {{#af_list: orange | banana | strawberry | apple }}
    }}
}}

Unfortunately, the above approach has a significant drawback: it can quickly lead to code that is difficult to read and maintain, because of the deep nesting. Luckily, MediaWiki offers a native solution to this problem: templates. Using templates, you can abstract away complex computations. Since ArrayFunctions is pure, these templates can be easily reused in various parts of your wiki, enhancing code readability and maintainability.

Example page Template:Sort and print
{{Sort and print|{{#af_list: orange | banana | strawberry | apple }} }}
{{#af_print: {{#af_sort: {{{1}}} }} }}