Skip to content

Commit

Permalink
list.removeWhere: keep table continuous by default
Browse files Browse the repository at this point in the history
  • Loading branch information
line0 committed Jan 2, 2016
1 parent 8b8c66a commit d524b15
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions Functional.moon
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d524b15

Please sign in to comment.