aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--containers.lua11
-rw-r--r--containers.moon3
2 files changed, 14 insertions, 0 deletions
diff --git a/containers.lua b/containers.lua
index 8f34e73..e706831 100644
--- a/containers.lua
+++ b/containers.lua
@@ -225,6 +225,17 @@ local _list_mt = {
end
return _accum_0
end)())
+ end,
+ reversed = function(self)
+ return List((function()
+ local _accum_0 = { }
+ local _len_0 = 1
+ for i = #self, 1, -1 do
+ _accum_0[_len_0] = self[i]
+ _len_0 = _len_0 + 1
+ end
+ return _accum_0
+ end)())
end
},
__newindex = function(self, k, v)
diff --git a/containers.moon b/containers.moon
index 2a9ee4b..6fa9ecb 100644
--- a/containers.moon
+++ b/containers.moon
@@ -88,6 +88,9 @@ _list_mt =
start = (n+1-start) if start < 0
stop = (n+1-stop) if stop < 0
return List[@[i] for i=start,stop]
+
+ reversed: => List[@[i] for i=#@,1,-1]
+
-- TODO: remove this safety check to get better performance?
__newindex: (k,v)=>
assert type(k) == 'number', "List indices must be numbers"