Exemplo n.º 1
0
 /** @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;
 }
Exemplo n.º 2
0
 /** @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;
 }
Exemplo n.º 3
0
 /** @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;
 }
Exemplo n.º 4
0
 /** @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;
 }
Exemplo n.º 5
0
 /** 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);
 }
Exemplo n.º 6
0
 /** @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;
 }