Module:Fun/doc
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
, as well as others.
lua
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
is not lua
, and use lua
. Otherwise, they will treat it as a hashmap, using lua
.
lua
lua
- Perform a function
on every element inlua
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 functionlua
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).lua
lua
- Create a new array from the results of performing a function on the values returned by an iterator. Can be used in combination with
in Module:table.lua
has the same signature described above. Not very useful withlua
;lua
would have alua
first argument, because the single value returned from the iterator would be supplied as the second argument tolua
.lua
mapIter( function(parameter_value, parameter_name) return { parameter_name, parameter_value } end, sortedPairs(frame.args)) --> returns a sorted array of arrays containing parameter names and values