Log In  

Cart #tablemap-0 | 2022-03-21 | Code ▽ | Embed ▽ | No License

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

P#77195 2022-03-21 08:51


[Please log in to post a comment]

Follow Lexaloffle:        
Generated 2022-05-04 14:55:15 | 0.006s | Q:13