/** * Return a new collection containing only the elements that satisfy predicate <code>p</code>. * * The type of collection <code>as</code> needs a parameterless constructor. * * @deprecated use {@link Monadics} */ @Deprecated public static <A, M extends Collection<A>> M filter(M as, Predicate<A> p) { @SuppressWarnings("unchecked") final M filtered = (M) buildFrom(as); for (A a : as) { if (p.apply(a)) filtered.add(a); } return filtered; }
/** * Apply a function <code>f</code> to all elements of collection <code>as</code> to produce a new collection * <code>bs</code> by concatenating the results. * * The type of collection <code>as</code> needs a parameterless constructor. * * Please note that since java does not support higher-order polymorphism -- which is needed to capture the type of * the collection -- some casting on the client side may still be necessary. * * @throws RuntimeException * if the result collection cannot be created * @deprecated use {@link Monadics} */ @Deprecated public static <A, B> Collection<B> flatMap(Collection<A> as, Function<A, Collection<B>> f) { Collection<B> bs = buildFrom(as); for (A a : as) { bs.addAll(f.apply(a)); } return bs; }
/** * Apply a function <code>f</code> to all elements of collection <code>as</code> to produce a new collection * <code>bs</code>. * * The type of collection <code>as</code> needs a parameterless constructor. * * Please note that since java does not support higher-order polymorphism -- which is needed to capture the type of * the collection -- some casting on the client side may still be necessary. * * @throws RuntimeException * if the target collection cannot be created * @deprecated use {@link Monadics} */ @Deprecated public static <A, B> Collection<B> map(Collection<A> as, Function<A, B> f) { Collection<B> b = buildFrom(as); for (A x : as) { b.add(f.apply(x)); } return b; }