https://linguifex.com/w/index.php?title=Module:Fun/doc&feed=atom&action=historyModule:Fun/doc - Revision history2024-03-28T22:57:58ZRevision history for this page on the wikiMediaWiki 1.39.1https://linguifex.com/w/index.php?title=Module:Fun/doc&diff=214876&oldid=prevChrysophylax: Created page with "<code>fun</code> stands for "functional", but also functional programming can be fun. This library contains some typical metafunctions for functional programming, such as {{co..."2021-01-02T04:34:58Z<p>Created page with "<code>fun</code> stands for "functional", but also functional programming can be fun. This library contains some typical metafunctions for functional programming, such as {{co..."</p>
<p><b>New page</b></p><div><code>fun</code> stands for "functional", but also functional programming can be fun. This library contains some typical metafunctions for functional programming, such as {{code|lua|map}}, {{code|lua|some}}, {{code|lua|all}}, {{code|lua|curry}}, as well as others.<br />
<br />
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.<br />
<br />
It was started in a user sandbox ([[Module:User:Erutuon/functional]]). It is not to be confused with [https://luafun.github.io Lua Fun] (of which there is a version at [[Module:User:Erutuon/luafun]]), even though some functions are similar.<br />
<br />
The functions that take a table as their second argument will treat the table as an array if {{code|lua|t[1]}} is not {{code|lua|nil}}, and use {{code|lua|ipairs}}. Otherwise, they will treat it as a hashmap, using {{code|lua|pairs}}.<br />
<br />
; {{code|lua|function map(func, iterable)}}<br />
: Perform a function {{code|lua|func}} on every element in {{code|lua|iterable}} and return the resulting table. {{code|lua|iterable}} 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 {{code|lua|func}} has the following signature: {{code|lua|func(member, i, iterable)}}. 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).<br />
; {{code|lua|function mapIter(func, iterator, iterable, initial_value)}}<br />
: Create a new array from the results of performing a function on the values returned by an iterator. Can be used in combination with {{code|lua|sortedPairs}} in [[Module:table]]. {{code|lua|func}} has the same signature described above. Not very useful with {{code|lua|gmatch}}; {{code|lua|func}} would have a {{code|lua|nil}} first argument, because the single value returned from the iterator would be supplied as the second argument to {{code|lua|func}}.<br />
: <source lang="lua"><br />
mapIter(<br />
function(parameter_value, parameter_name)<br />
return { parameter_name, parameter_value }<br />
end,<br />
sortedPairs(frame.args))<br />
--> returns a sorted array of arrays containing parameter names and values<br />
</source><br />
<br />
<includeonly><br />
[[Category:Lua metamodules]]<br />
</includeonly></div>Chrysophylax