/** @return Any x : p(x) == true */ public static <A> boolean any(Map1<A, Boolean> p, Collection<A> xs) { for (A x : xs) if (p.apply(x)) return true; return false; }
/** @return the first x in items that satisfies take(x), or null if none */ public static <X> X find(Map1<X, Boolean> take, final Collection<X> xs) { for (X x : xs) if (take.apply(x)) return x; return null; }
/** @return [x | x <- items, take(x)] */ public static <A> Set<A> filterSet(Map1<A, Boolean> take, final Collection<A> xs) { Set<A> rs = new HashSet<A>(xs.size()); for (A x : xs) if (take.apply(x)) rs.add(x); return rs; }
/** @return [x | x <- items, take(x)] */ public static <A> List<A> filter(Map1<A, Boolean> take, final Collection<A> xs) { List<A> rs = new ArrayList<A>(xs.size()); for (A x : xs) if (take.apply(x)) rs.add(x); return rs; }
/** Same as map, but does not retain results. */ public static <A> void each(Map1<A, ?> fn, final Collection<A> xs) { for (A x : xs) fn.apply(x); }
/** @return [fn(x) | x <- items] */ public static <A, B> List<B> map(Map1<A, B> fn, final Collection<A> xs) { ArrayList<B> rs = new ArrayList<B>(xs.size()); for (A x : xs) rs.add(fn.apply(x)); return rs; }