Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/stevedonovan/Penlight.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsteve donovan <steve.j.donovan@gmail.com>2011-04-05 19:03:34 +0400
committersteve donovan <steve.j.donovan@gmail.com>2011-04-05 19:03:34 +0400
commitba056786e2a2a07c4a57bccb0a8bd1ad63787c9f (patch)
tree06c8017266496569085a11dac20347f1586783df /lua/pl/seq.lua
parentff0ad71640c03978735deb963788beb14ac65187 (diff)
miscelaneous fixes and reformatting
Diffstat (limited to 'lua/pl/seq.lua')
-rw-r--r--lua/pl/seq.lua12
1 files changed, 7 insertions, 5 deletions
diff --git a/lua/pl/seq.lua b/lua/pl/seq.lua
index c182b7a..20731f2 100644
--- a/lua/pl/seq.lua
+++ b/lua/pl/seq.lua
@@ -112,8 +112,8 @@ end
-- @param optional argument to be passed to predicate as second argument.
function seq.count(iter,condn,arg)
local i = 0
- foreach(iter,function(val)
- if condn(v,arg) then i = i + 1 end
+ seq.foreach(iter,function(val)
+ if condn(val,arg) then i = i + 1 end
end)
return i
end
@@ -148,7 +148,7 @@ end
-- @param iter a sequence
-- @return a List
-- @usage copy(list(ls)) is equal to ls
--- @usage copy(list {1,2,3},List) == List{1,2,3}
+-- @usage copy(list {1,2,3}) == List{1,2,3}
function seq.copy(iter)
local res = {}
for v in default_iter(iter) do
@@ -255,6 +255,7 @@ function seq.unique(iter,returns_table)
local t = count_map(iter)
local res = {}
for k in pairs(t) do tappend(res,k) end
+ table.sort(res)
if returns_table then
return res
else
@@ -361,7 +362,7 @@ function seq.reduce (fun,seq,oldval)
end
local val = seq()
if val==nil then return oldval
- else return fun(oldval,reduce(fun,seq,val))
+ else return fun(oldval,seq.reduce(fun,seq,val))
end
end
@@ -461,6 +462,7 @@ end
-- can't directly look these up in seq because of the wrong argument order...
+local map,reduce,mapmethod = seq.map, seq.reduce, seq.mapmethod
local overrides = {
map = function(self,fun,arg)
return map(fun,self,arg)
@@ -487,7 +489,7 @@ SMT = {
setmetatable(seq,{
__call = function(tbl,iter)
if not callable(iter) then
- if type(iter) == 'table' then iter = list(iter)
+ if type(iter) == 'table' then iter = seq.list(iter)
else return iter
end
end