Introducing some of the goodness of collection operations to our codebase without adding a new external library dependency, we are adding these methods to our utility package.
static public List<T> filter(List<T> source, Predicate<T> filter);
static <Y,T> public List<Y> transform(List<T> source, Mutator<Y,T> filter);
static public boolean exists(List<T> source, Predicate<T> filter);
static public T findFirst(List<T> source, Predicate<T> filter);
static public boolean trueForAll(List<T> source, Predicate<T> filter);
With the attendant interfaces
public interface Predicate<T> { public boolean apply(T item); }
public interface Mutator<T,Y> { public Y apply(T item); }
So the questions:
Edited to add: A significant argument I have against map (and thus in favor of transform) is that map has significant semantic load due to the many uses for java.util.Map
Are there any important set-based functions that I've forgotten to include in the library class?
For higher-order collection functions I use the approach outlined by Adrian Kuhn in his article "Pimp My Foreach".
Some of these you've already got, but thought I'd throw them out there anyway:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With