Functional Utilities

Simple Function construction and manipulation methods are provided in Functions, including

  • forMap(Map<A, B>)
  • compose(Function<B, C>, Function<A, B>)
  • constant(T)
  • identity()
  • toStringFunction()

There are considerably more construction and manipulation methods available in Predicates, but a sample includes:

  • instanceOf(Class)
  • assignableFrom(Class)
  • contains(Pattern)
  • in(Collection)
  • isNull()
  • alwaysFalse(), alwaysTrue()
  • equalTo(Object)
  • compose(Predicate, Function)
  • and(Predicate...), or(Predicate...), not(Predicate)
Multiset<Integer> lengths = HashMultiset.create(
  FluentIterable.from(strings)
    .filter(new Predicate<String>() {
       public boolean apply(String string) {
         return CharMatcher.javaUpperCase().matchesAllOf(string);
       }
     })
    .transform(new Function<String, Integer>() {
       public Integer apply(String string) {
         return string.length();
       }
     }));

results matching ""

    No results matching ""