sorcery  Diff

Differences From Artifact [d54be79f29]:

To Artifact [990a6e8caf]:


   206    206   end
   207    207   
   208    208   fn.cond = function(exp, c)
   209    209   	for i, v in ipairs(c) do
   210    210   		if c[1](exp) then return c[2](exp) end
   211    211   	end
   212    212   end
          213  +
          214  +fn.select = function(tbl, prop, ...)
          215  +	local keycache
          216  +	local check if type(prop) == 'function' then
          217  +		check = prop
          218  +		keycache = ...
          219  +	else
          220  +		local val val, keycache = ...
          221  +		check = function(ent) return ent[prop] == val end
          222  +	end
          223  +	for k,v in pairs(tbl) do
          224  +		if (not keycache) or (not keycache[k]) then -- help avoid expensive selectors
          225  +			if check(v,k) then
          226  +				if keycache then keycache[k] = true end
          227  +				return v, k
          228  +			end
          229  +		end
          230  +	end
          231  +end
   213    232   
   214    233   return fn