From d524b151651cb8ab1b991ad47b4c03277e5e4d68 Mon Sep 17 00:00:00 2001 From: line0 Date: Sat, 2 Jan 2016 16:16:19 +0100 Subject: [PATCH] list.removeWhere: keep table continuous by default --- Functional.moon | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Functional.moon b/Functional.moon index a3dfad8..faa627f 100644 --- a/Functional.moon +++ b/Functional.moon @@ -180,15 +180,20 @@ list = setmetatable { i += 1 return removed, shift - removeWhere: (tbl, predicate = _function.true) -> + removeWhere: (tbl, predicate = _function.true, sparse = false) -> removeAll = predicate == _function.true removed, r = {}, 0 for i, v in ipairs tbl if removeAll or predicate v, i, tbl r += 1 - removed[r], tbl[i] = v + if sparse + removed[r], tbl[i] = v + else removed[r] = i - return removed, r + if sparse + return removed, r + else + return list.removeIndexes(tbl, removed), r slice: (tbl, first = 1, last = -1) -> len = #tbl