Create an Iterable view of the specified Iterable that only contains
elements that match the predicate.
This Iterable can be iterated over at any time in the future to
view the current predicate-matching elements of the input Iterable.
973336
public <E extends T> Iterable<E> createView (final Iterable<E> input)
    {
        return new Iterable<E>() {
            public Iterator<E> iterator() {
                return filter(input.iterator());
            }
        };
    }
232980
public static <T> List<T> filter(final Iterable<T> unfiltered, final Predicate<T> filter) {
        return newArrayList(Iterables.filter(unfiltered, filter));
    }
911090
@SuppressWarnings("unchecked")
  public static Iterator<Object> iterator(Object iterable) {
    Assert.state(isIterable(iterable.getClass()));
    return iterable.getClass().isArray() ? new ArrayIterator(iterable)
        : ((Iterable<Object>) iterable).iterator();
  }
104066
public static <T> Set<T> toSet(Iterable<T> iterable)
   {
      if (iterable == null)
      {
         return null;
      }
      else if (iterable instanceof Set)
      {
         return (Set<T>) iterable;
      }
      else
      {
         Set<T> list = new LinkedHashSet<>();
         for (T obj : iterable)
         {
            list.add(obj);
         }
         return list;
      }
   }
23055
private static <E> List<E> toList(Iterable<E> iterable)
	{
		List<E> list = new ArrayList<>();
		iterable.forEach(list::add);
		return list;
	}
925597
public static <T> List<T> asList(Iterable<T> iterable) {
        List<T> result = new ArrayList<>();
        for (T item : iterable) {
            result.add(item);
        }
        return result;
    }
1161265
public static <T> Set<T> iterableToSet(Iterable<T> iterable) {
        if (iterable == null) {
            return Collections.emptySet();
        }
        if (iterable instanceof Set) {
            return (Set<T>) iterable;
        }
        Iterator<T> i = iterable.iterator();
        if (i.hasNext()) {
            Set<T> list = new HashSet<>();
            while (i.hasNext()) {
                list.add(i.next());
            }
            return list;
        }
        return Collections.emptySet();
    }
1001220
public static <T> Maybe<T> fromIterable(Iterable<T> t) {
        return narrow(Single.fromPublisher(Future.fromIterable(t)).toMaybe());
    }
309310
public static <T, P, R extends Collection<T>> R selectWith(
            Iterable<T> iterable,
            Predicate2<? super T, ? super P> predicate,
            P parameter,
            R targetCollection)
    {
        if (iterable instanceof RichIterable)
        {
            return ((RichIterable<T>) iterable).selectWith(predicate, parameter, targetCollection);
        }
        if (iterable instanceof ArrayList)
        {
            return ArrayListIterate.selectWith((ArrayList<T>) iterable, predicate, parameter, targetCollection);
        }
        if (iterable instanceof List)
        {
            return ListIterate.selectWith((List<T>) iterable, predicate, parameter, targetCollection);
        }
        if (iterable != null)
        {
            return IterableIterate.selectWith(iterable, predicate, parameter, targetCollection);
        }
        throw new IllegalArgumentException("Cannot perform a selectWith on null");
    }
701365
public static <T> Iterable<T> cast(Iterable<?> iterable) {
    return iterable == null ? null : new CastingIterable<T>(iterable);
  }
1005592
public static Predicates<Object> in(Iterable<?> iterable)
    {
        if (iterable instanceof SetIterable<?>)
        {
            return new InSetIterablePredicate((SetIterable<?>) iterable);
        }
        if (iterable instanceof Set<?>)
        {
            return new InSetPredicate((Set<?>) iterable);
        }
        if (iterable instanceof Collection<?> && ((Collection<?>) iterable).size() <= SMALL_COLLECTION_THRESHOLD)
        {
            return new InCollectionPredicate((Collection<?>) iterable);
        }
        return new InSetIterablePredicate(UnifiedSet.newSet(iterable));
    }
720774
def where(self, predicate):
        
        if predicate is None:
            raise NullArgumentError("No predicate given for where clause")
        return Enumerable(itertools.ifilter(predicate, self))
467482
public static boolean contains(Iterable<?> iterable, Object value)
    {
        if (iterable instanceof Collection)
        {
            return ((Collection<?>) iterable).contains(value);
        }
        if (iterable instanceof RichIterable)
        {
            return ((RichIterable<?>) iterable).contains(value);
        }
        return IterableIterate.detectIndex(iterable, Predicates.equal(value)) > -1;
    }
244933
public static <T> List<T> filter( Iterable<T> collection, Predicate<T> predicate)
    {
        List<T> filtered = new ArrayList<T>();
        for (T element : collection)
        {
        	if (predicate.isVerifiedBy(element))
        	{
        		filtered.add(element);
        	}
        }
        return filtered;
    }
562525
def unique(iterable):
    
    seen = set()
    for obj in iterable:
        if obj not in seen:
            yield obj
            seen.add(obj)
544769
public static <E> Optional<E> find(final Iterable<E> iterable, final Predicate<E> pred) {
        for (E element : iterable) {
            if (pred.test(element)) {
                return Optional.of(element);
            }
        }
        return Optional.absent();
    }
880643
def uniqued(iterable):
    
    seen = set()
    add = seen.add
    return [i for i in iterable if i not in seen and not add(i)]