Iterable<T> に、Predicate<T> を指定する形で生成する。
public static <T> Iterable<T> selectIterable(Iterable<T> it, Predicate<T> pred) { return () -> new Iterator<T>(){ Iterator<T> sourceIterator = it.iterator(); T current; boolean hasCurrent = false; @Override public boolean hasNext(){ while(!hasCurrent){ if (!sourceIterator.hasNext()){ return false; } T next = sourceIterator.next(); if (pred.test(next)){ current = next; hasCurrent = true; } } return true; } @Override public T next() { if (!hasNext()) throw new NoSuchElementException(); hasCurrent = false; return current; } }; }