Add new utility function

This commit is contained in:
Emik 2026-06-16 21:22:05 +02:00
parent 15a50ff9d1
commit d49f446d6e
Signed by: emik
GPG key ID: 6B0CD72A5E503BDF

View file

@ -200,6 +200,16 @@ function f.index(v)
end
end
---@generic K, V
---@param v { [K]: V }
---@return fun(x: K): V
---@nodiscard
function f.index_into(v)
return type(v) == "table" and function(x)
return v[x]
end or f.const(v)
end
---@generic V
---@param v string
---@return fun(x: { [string]: V }): V
@ -257,6 +267,7 @@ function f.new(fnext)
from = f.from,
id = f.id,
index = f.index,
index_into = f.index_into,
indices = f.indices,
keys = f.keys,
map = f.map,