diff options
author | Hisham Muhammad <hisham@gobolinux.org> | 2018-07-01 21:27:36 -0300 |
---|---|---|
committer | Hisham Muhammad <hisham@gobolinux.org> | 2018-07-01 22:54:08 -0300 |
commit | fbf60599a04cddab512e5e95165fe875d8c01303 (patch) | |
tree | 3ab25eff079068f01ce2d829932356b6b855c1f9 /src | |
parent | a0e2ba8649305a0309edebd3cc74da23a39785d7 (diff) | |
download | luarocks-fbf60599a04cddab512e5e95165fe875d8c01303.tar.gz luarocks-fbf60599a04cddab512e5e95165fe875d8c01303.tar.bz2 luarocks-fbf60599a04cddab512e5e95165fe875d8c01303.zip |
fun: add reverse_in and sort_in
* reverse_in: reverse table in-place
* sort_in: sort table in-place
Diffstat (limited to 'src')
-rw-r--r-- | src/luarocks/fun.lua | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/luarocks/fun.lua b/src/luarocks/fun.lua index 9ba02bf5..dfdf36ed 100644 --- a/src/luarocks/fun.lua +++ b/src/luarocks/fun.lua | |||
@@ -48,4 +48,19 @@ function fun.traverse(t, f) | |||
48 | end) | 48 | end) |
49 | end | 49 | end |
50 | 50 | ||
51 | function fun.reverse_in(t) | ||
52 | for i = 1, math.floor(#t/2) do | ||
53 | local m, n = i, #t - i + 1 | ||
54 | local a, b = t[m], t[n] | ||
55 | t[m] = b | ||
56 | t[n] = a | ||
57 | end | ||
58 | return t | ||
59 | end | ||
60 | |||
61 | function fun.sort_in(t, f) | ||
62 | table.sort(t, f) | ||
63 | return t | ||
64 | end | ||
65 | |||
51 | return fun | 66 | return fun |