CollectionPattern<T> (final ElementPattern<? extends T> elementPattern, final ElementPattern<Collection<T>> continuationPattern) { return with(new PatternCondition<Collection<T>>("filter") { @Override public boolean accepts(final @NotNull Collection<T> collection, final ProcessingContext context) { List<T> filtered = new ArrayList<>(); for (final T t : collection) { if (elementPattern.accepts(t, context)) { filtered.add(t); } } return continuationPattern.accepts(filtered, context); } }); }