global.function-or
Signature
v | f == f(v)
The pipe operator applies a value to a function.
Note: because pipes are expressions in Lua, this cannot be used as a statement. To use this operator to cause side-effects, assign the result to a dummy variable.
Examples
print(3 | function(a) return a+4 end) -- 7
for n in {1, 2, 3, 4, 5}
| lowk.iter.fromarray
| lowk.iter.filter(function(n) return n%2 == 0 end)
do
print(n)
end
-- 2
-- 4
local t = {1, 2, 3, 4, 5}
| lowk.iter.fromarray
| lowk.iter.filter(function(n) return n%2 == 0 end)
| lowk.iter.toarray
for i,v in ipairs(t) do
print(i, v)
end
-- 1 2
-- 2 4