#1960 Add List.removeAll

Akcelisto Thu 19 Jul 2012

May be add removeAll and removeSameAll to sys::List?

brian Thu 19 Jul 2012

My initial thought is that would be sort of obscure one since its easily done in loop. I'd say we add if some other people chime in and say they would like to see it too.

Yuri Strot Thu 19 Jul 2012

I think removeAll must be there. When we have addAll and haven't removeAll it looks inconsistent. Another reason is that removeAll has potential for performance improvements (no need to shift bytes after each element remove). Even without low-level optimization when I need to implement removeAll on my own I prefer to use list.each { remove(it) } which is much slower than native implementation.

brian Thu 19 Jul 2012

Promoted to ticket #1960 and assigned to brian

I see now - I thought removeAll was already there, and removeAllSame was what we discussing to add. I agree we should definitely add removeAll.

So should also have removeAllSame too?

KevinKelley Thu 19 Jul 2012

I'd nuke the removeSame... these can all be simulated with findAll |v->Bool| { v !== item } or similar...

The only thing is that this is the functional style (return a new, modified list) vs. the OO style (modify list in-place). Since both styles need to be supported, then it seems reasonable to have most-efficient implementations, like addAll and removeAll. But since there's already another way, I don't see the need to spell out all the permutations.

Since List is such a "use-it-for-everything" kind of thing, it's really easy for it to get bloated.

go4 Fri 20 Jul 2012

The removeAll sounds like the List::clear. I prefer to removeWhile.

list.each { remove(it) }

Can I modify the list in the iteration?

brian Mon 15 Oct 2012

Renamed from lack of removeAll and removeAllSame in sys::List to Add List.removeAll

brian Mon 15 Oct 2012

Ticket resolved in 1.0.64

Added List.removeAll:

**
** Remove every item in this list which is found in the 'toRemove' list using
** same semantics as `remove` (compare for equality via the == operator).
** If any value is not found, it is ignored.  Return this.
** Throw ReadonlyErr if readonly.
**
L removeAll(L list)

changeset

Login or Signup to reply.