Skip to content

Commit

Permalink
Fixed Iterable:select
Browse files Browse the repository at this point in the history
  • Loading branch information
SinisterRectus committed Aug 1, 2017
1 parent 1521024 commit 04c1326
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions libs/iterables/Iterable.lua
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,20 @@ function Iterable:random()
end
end

local function compare(a, b)
return a < b
end

local function sorter(a, b)
local t = type(a)
if t == 'string' then
return (tonumber(a) or a) < (tonumber(b) or b)
elseif t == 'number' then
local t1, t2 = type(a), type(b)
if t1 == 'string' and t2 == 'string' then
return (tonumber(a) or a:lower()) < (tonumber(b) or b:lower())
elseif t1 == 'number' and t2 == 'number' then
return a < b
else
local mt = getmetatable(a)
if mt and mt.__lt then
return a < b
local success, ret = pcall(compare)
if success then
return ret
else
return tostring(a) < tostring(b)
end
Expand All @@ -95,7 +99,7 @@ function Iterable:select(...)
for obj in self:iter() do
local row = {}
for i = 1, keys.n do
insert(row, obj[keys[i]])
row[i] = obj[keys[i]]
end
insert(rows, row)
end
Expand Down

0 comments on commit 04c1326

Please sign in to comment.