From 0b991d7ea58ece71f358741e3f0d28bb085040d6 Mon Sep 17 00:00:00 2001 From: rxi Date: Fri, 12 Dec 2014 18:56:13 +0000 Subject: [PATCH] Added identity() and iteratee() local funcs --- lume.lua | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lume.lua b/lume.lua index 73f1e9e..c868992 100644 --- a/lume.lua +++ b/lume.lua @@ -35,6 +35,24 @@ local iscallable = function(x) return mt and mt.__call ~= nil end +local identity = function(x) + return x +end + +local iteratee = function(x) + if x == nil then return identity end + if iscallable(x) then return x end + if type(x) == "table" then + return function(z) + for k, v in pairs(x) do + if z[k] ~= v then return false end + end + return true + end + end + return function(z) return z[x] end +end + function lume.clamp(x, min, max)