Log In  

Cart #tablemap-1 | 2023-05-28 | Code ▽ | Embed ▽ | No License
1

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

  • 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.

v0.1

  • first release
P#77195 2022-03-21 08:51 ( Edited 2023-05-28 14:02)

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.
P#130249 2023-05-28 14:03

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-03-28 11:38:06 | 0.026s | Q:12