mirror of
https://github.com/1bardesign/batteries.git
synced 2024-11-14 04:01:48 +00:00
disambiguated variable names in map_call
This commit is contained in:
parent
b68081be53
commit
bff54f0dbd
@ -99,15 +99,15 @@ function functional.map_field(t, k)
|
|||||||
return result
|
return result
|
||||||
end
|
end
|
||||||
|
|
||||||
--maps a sequence
|
--maps a sequence by a method call
|
||||||
-- if f is a string method name like "position", {a, b} -> {a:f(...), b:f(...)}
|
-- if m is a string method name like "position", {a, b} -> {a:m(...), b:m(...)}
|
||||||
-- if f is function reference like player.get_position, {a, b} -> {f(a, ...), f(b, ...)}
|
-- if m is function reference like player.get_position, {a, b} -> {m(a, ...), m(b, ...)}
|
||||||
-- (automatically drops any nils to keep a sequence)
|
-- (automatically drops any nils to keep a sequence)
|
||||||
function functional.map_call(t, f, ...)
|
function functional.map_call(t, m, ...)
|
||||||
local result = {}
|
local result = {}
|
||||||
for i = 1, #t do
|
for i = 1, #t do
|
||||||
local v = t[i]
|
local v = t[i]
|
||||||
local f = type(f) == "function" and f or v[f]
|
local f = type(m) == "function" and m or v[m]
|
||||||
v = f(v, ...)
|
v = f(v, ...)
|
||||||
if v ~= nil then
|
if v ~= nil then
|
||||||
table.insert(result, v)
|
table.insert(result, v)
|
||||||
|
Loading…
Reference in New Issue
Block a user