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:
- Is Filters a good name for the class containing the extensions? If not, a better?
- Is Mutator<T,Y> appropriately named?
- Should I prefer map to transform and reduce to filter?
- Are there any important set-based functions that I've forgotten to include in the library class?
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