Add new utility function
This commit is contained in:
parent
15a50ff9d1
commit
d49f446d6e
1 changed files with 11 additions and 0 deletions
|
|
@ -200,6 +200,16 @@ function f.index(v)
|
||||||
end
|
end
|
||||||
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
|
---@generic V
|
||||||
---@param v string
|
---@param v string
|
||||||
---@return fun(x: { [string]: V }): V
|
---@return fun(x: { [string]: V }): V
|
||||||
|
|
@ -257,6 +267,7 @@ function f.new(fnext)
|
||||||
from = f.from,
|
from = f.from,
|
||||||
id = f.id,
|
id = f.id,
|
||||||
index = f.index,
|
index = f.index,
|
||||||
|
index_into = f.index_into,
|
||||||
indices = f.indices,
|
indices = f.indices,
|
||||||
keys = f.keys,
|
keys = f.keys,
|
||||||
map = f.map,
|
map = f.map,
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue