My favorites | Sign in
Project Home Downloads Wiki Issues Source
Project Information
Members
Links

Functional extension of google collections

Write more fluent code with functional collections, eg :

map and select

FunctionalIterable<String> longerThan3 = FunctionalIterables.make(source).map(new Function<Object, String>() {
    public String apply(Object from) {
        return from.toString();
    }
}).select(new Predicate<String>() 
{
    public boolean apply(String input) {
        return input.length() > 3;
    }
});
                 

inject

Integer initial = 0;
                
Integer totalLength = FunctionalIterables.make(source).inject(initial, new Injector<Integer, String>() {
    public Integer apply(Integer memo, String input) {
        return memo + input.length();
    }
});

join

String expected = "1, 2, 3, 4, 5";
String joined = FunctionalIterables.make(1, 2, null, 3, 4, 5).join(Joiner.on(", ").skipNulls());
assertEquals(expected, joined);
Powered by Google Project Hosting