From Linguifex
Jump to: navigation, search

This is the documentation page for Module:Fun

fun stands for "functional", but also functional programming can be fun. This library contains some typical metafunctions for functional programming, such as lua, lua, lua, lua, as well as others.

Functions that take an array as their second argument are available as methods in the arrays created by Module:array, with the arguments reversed so that they can be called as methods.

It was started in a user sandbox (Module:User:Erutuon/functional). It is not to be confused with Lua Fun (of which there is a version at Module:User:Erutuon/luafun), even though some functions are similar.

The functions that take a table as their second argument will treat the table as an array if lua is not lua, and use lua. Otherwise, they will treat it as a hashmap, using lua.

Perform a function lua on every element in lua and return the resulting table. lua may be a table or a string. If a table, the function operates on every element in the array portion of the table; if a string, the function operates on every UTF-8 character in the string. The function lua has the following signature: lua. That is, the table element or UTF-8 character is first, then the index of this element, and then the iterable value (table or string).
Create a new array from the results of performing a function on the values returned by an iterator. Can be used in combination with lua in Module:table. lua has the same signature described above. Not very useful with lua; lua would have a lua first argument, because the single value returned from the iterator would be supplied as the second argument to lua.
    function(parameter_value, parameter_name)
        return { parameter_name, parameter_value }
--> returns a sorted array of arrays containing parameter names and values