From d49f446d6ea8f1e88ff07357c19ed0ed3110336d Mon Sep 17 00:00:00 2001 From: Emik Date: Tue, 16 Jun 2026 21:22:05 +0200 Subject: [PATCH] Add new utility function --- src/lib/funky.lua | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/lib/funky.lua b/src/lib/funky.lua index a5e20de..0333c62 100644 --- a/src/lib/funky.lua +++ b/src/lib/funky.lua @@ -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,