1

On regular java collections it's possible to remove an element given an input Predicate. persons.removeIf(person -> person.isMale());

In eclipse collections it seems possible to do this as long as the collection being used extends Iterable<T>.

For primitive collections that extend PrimitiveIterable, there doesn't seem to be a method provided to do the same. Is it not supported? If not, why?

EDIT: I should add that I'm looking for a method that removes an item in-place without creating a new set, as reject does.

Vivek Rao
  • 576
  • 4
  • 25
  • Well, `removeIf` didn't get added onto the interface until Java 8... – Louis Wasserman Oct 16 '17 at 22:57
  • *"Is it not supported?"* **Read the documentation**. Seems you're looking for [`MutableIntCollection.reject​(IntPredicate predicate)`](http://www.eclipse.org/collections/javadoc/9.0.0/org/eclipse/collections/api/collection/primitive/MutableIntCollection.html#reject-org.eclipse.collections.api.block.predicate.primitive.IntPredicate-), or one of it's cousins. http://idownvotedbecau.se/noresearch/ – Andreas Oct 16 '17 at 23:14
  • I did look at the documentation. Perhaps my question wasn't clear enough, I want something that removes an element in place. ```reject``` returns a new set with the elements that did not match. – Vivek Rao Oct 17 '17 at 14:35

1 Answers1

3

The method removeIf doesn't exist for mutable primitive collections in Eclipse Collections today. It makes sense to add, as it has been on the mutable object collections since at least version 2.0 which was released in August 2012. I just started working on it. It can be added as a default method so should hopefully be available in the 9.1 release.

Update: The method removeIf was added to mutable primitive collections in the 9.1 release of Eclipse Collections.

Donald Raab
  • 6,458
  • 2
  • 36
  • 44
  • Pull request for this has been merged so will be in next release: https://github.com/eclipse/eclipse-collections/pull/377 – Donald Raab Nov 01 '17 at 21:01