yangxu998 / guava-libraries

Automatically exported from code.google.com/p/guava-libraries
Apache License 2.0
0 stars 0 forks source link

Predicates functions for Iterables #650

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Add the 3 followings functions to Predicates or in a IterablePredicates to 
handle predicates on Iterable<T>.

public class IterablePredicates {
    public static <T> Predicate<Iterable<T>> any(final Predicate<T> predicate)
    {
        return new Predicate<Iterable<T>>() {
            @Override
            public boolean apply(final Iterable<T> input)
            {
                return Iterables.any(input, predicate);
            }
        };
    }

    public static <T> Predicate<Iterable<T>> all(final Predicate<T> predicate)
    {
        return new Predicate<Iterable<T>>() {
            @Override
            public boolean apply(final Iterable<T> input)
            {
                return Iterables.all(input, predicate);
            }
        };
    }

    public static <T> Predicate<Iterable<T>> isEmpty()
    {
        return new Predicate<Iterable<T>>() {
            @Override
            public boolean apply(final Iterable<T> input)
            {
                return Iterables.isEmpty(input);
            }
        };
    }
}

Original issue reported on code.google.com by alexandr...@gmail.com on 5 Jul 2011 at 9:45

GoogleCodeExporter commented 9 years ago
This reminds me of hamcrest matchers. It looks usable to me, ut it is kind of 
easy to implement, so the question is, if it will benefit the guava library to 
add those functions.

Original comment by gscerbak@gmail.com on 6 Jul 2011 at 11:01

GoogleCodeExporter commented 9 years ago
We don't want Guava to end up consisting of 50% actual methods and 50% 
Function/Predicate wrappers for those same actual methods. So, so far we are 
accepting these kind of wrappers on a case-by-case basis, where the broad 
applicability really is clear.

This one seems unlikely to clear the bar to me, but I do think that Java 8 will 
change everything in this regard anyway.

Original comment by kevinb@google.com on 13 Jul 2011 at 6:35

GoogleCodeExporter commented 9 years ago
This issue has been migrated to GitHub.

It can be found at https://github.com/google/guava/issues/<id>

Original comment by cgdecker@google.com on 1 Nov 2014 at 4:15

GoogleCodeExporter commented 9 years ago

Original comment by cgdecker@google.com on 3 Nov 2014 at 9:09