Extension:ArrayFunctions/Essentials/Composing functions

ArrayFunctions is designed to be stateless, meaning that it does not store values in memory. Instead, values are computed and outputted by the parser function. 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 fundamentally makes using it fundamentally different compared to other extensions. Rather than imperatively modifying an array stored in a variable, users must rely on function composition to perform complex operations. For example:

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

Composing templates

edit

Unfortunately, the above approach has a significant drawback: it can quickly lead to code that is difficult to read and maintain. Luckily, MediaWiki offers a native solution to this problem: templates!

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

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.