I am using the guava library and have noticed that a very useful Predicate is not defined - "greater than". Is there another place I should be looking for basic predicates like this, or am I doomed to create my own functional support jar that includes things like this, and import it into all of my projects? Is there a reason they wouldn't include this,but would take the time to do a bunch of other predicates (In the Predicates class)?
Range and Ranges (update: the static methods on Ranges
have been folded into Range
as of Guava 14.0) have now been added for r10. You'll be able to just do:
Iterable<Integer> positive = Iterables.filter(numbers, Range.greaterThan(0));
Range
s have a lot of other powerful functionality, including the ability to view a Range
as a contiguous ImmutableSortedSet
over a discrete domain:
ContiguousSet<Integer> oneToOneHundred = ContiguousSet.create(
Range.closed(1, 100), DiscreteDomains.integers());
I just showed Integer
s here, but the Range
stuff works for any Comparable
. ContiguousSet
requires a DiscreteDomain for the type... Guava provides DiscreteDomain.integers()
, .longs()
and .bigIntegers()
at the moment.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With