Feature Overview
TMAP(), like foreach(), applies the function of the second argument to each element of the table.
- Usage is almost the same as foreach(), plus index values can be referenced within the function.
- The specified table is returned. (TMAP() nested functions can be applied multiply)
- The return value in the function specified in the argument can update each element of the table.
- This function consumes 31 Token.
local t={ 'toast' ,'letus' ,'bacon' ,'cheese' } t=tmap(t, function(v,i) ?i..'..'..v end) -------- t=tmap(t, function(v,i) v='super★'..v ?i..'..'..v return v end) -------- t=tmap({ 'shield' ,'armor' ,'sword' ,'ring' }, function(v,i) v=t[i]..'•'..v ?i..'..'..v return v end) |
may want to Use DMP() if check the converted table.
This function is included in the KNUTIL library.
release note
v0.2 version update contents.
- support for updating table elements to false.
- documentation was adapted to other library formats.
- the previous version of the code was commented out as the shortest version.
[Please log in to post a comment]