Rapidoid - Extremely Fast, Simple and Powerful Java Web Framework!

Rapidoid consists of several modules which can be used separately or together:
Add rapidoid-fluent as Maven dependency:
<dependency>
    <groupId>org.rapidoid</groupId>
    <artifactId>rapidoid-fluent</artifactId>
    <version>5.2.8</version>
</dependency>
Module rapidoid-fluent

Fluent API for Elegant Stream Manipulation

~ 80% test coverage. Self-contained. 33 KB JAR size.
  • Lightweight fluent DSL for elegant manipulation of collections and streams.
// Using Java 8? Now you can EASILY filter, map, group and search through collections:
Find.firstOf(items).where(s -> s.length() < 3);
 
Find.allOf(nums).where((k, v) -> k > 1);
 
For.each(books).withNonNull(Book::title).run(this::publish);
 
Do.map(words).to(s -> s.length());
 
Do.group(items).by(Item::getCategory);
 
Do.reduce(words).by((a, b) -> a + ":" + b).orElse("");
 
Do.map(nums).toList((k, v) -> k * 2);
Map<Integer, String> nums = New.map(1, "one", 2, "two", 3, "three");{"1":"one","2":"two","3":"three"}
 
// Find the even numbers from the map - with Rapidoid Fluent (and Java 8 streams behind the scenes):
Find.allOf(nums).where((k, v) -> k % 2 == 0);{"2":"two"}
 
// That is equivalent to the following code:
Map<Integer, String> even = nums.entrySet().stream()
        .filter(num -> num.getKey() % 2 == 0)
        .collect(Collectors.toMap(Entry::getKey, Entry::getValue));
 
System.out.println(even);{"2":"two"}
 
// Or, we can do the same thing in the old way
Map<Integer, String> even2 = new HashMap<>();
 
for (Entry<Integer, String> num : nums.entrySet()) {
    int k = num.getKey();
    if (k % 2 == 0) {
        even2.put(k, num.getValue());
    }
}
 
System.out.println(even2);{"2":"two"}
// Map
 
List<String> items = New.list("a", "bbbbb", "cc");["a","bbbbb","cc"]
 
Do.map(items).to(s -> s.length());[1,5,2]
 
// Reduce
Do.reduce(items).by((a, b) -> a + ":" + b).orElse("");"a:bbbbb:cc"
 
Do.reduce(items).by("@", (a, b) -> a + ":" + b);"@:a:bbbbb:cc"
 
// Group-by
Do.group(items).by(s -> s.length());{"1":["a"],"2":["cc"],"5":["bbbbb"]}
Map<Integer, String> nums = New.map(1, "one", 2, "two", 3, "three");{"1":"one","2":"two","3":"three"}
 
// Map
Do.map(nums).to((k, v) -> k * 1000, (k, v) -> v.toUpperCase());{"1000":"ONE","2000":"TWO","3000":"THREE"}
 
Do.map(nums).toList((k, v) -> k * 2);[2,4,6]
 
Do.map(nums).toSet((k, v) -> v.length());[3,5]
 
// Group-by
Do.group(nums).by((k, v) -> k % 2 == 0 ? "even" : "odd");{"even":{"2":"two"},"odd":{"1":"one","3":"three"}}
List<String> items = New.list("a", "bbb", "cc");["a","bbb","cc"]
 
List<String> dest = New.list();
 
For.each(items).where(s -> s.length() < 3).run(dest::add);
 
System.out.println(dest);["a","cc"]
// Searching through lists or sets:
 
List<String> items = New.list("a", "bbbbb", "cc");["a","bbbbb","cc"]
 
Find.firstOf(items).where(s -> s.length() < 3);"a"
 
Find.lastOf(items).where(s -> s.length() > 4);"bbbbb"
 
Find.anyOf(items).where(s -> s.length() == 5);"bbbbb"
 
Find.allOf(items).where(s -> s.length() > 1);["bbbbb","cc"]
 
Find.in(items).where(s -> s.length() < 5);true
 
Find.in(items.stream()).where(s -> s.length() > 10);false
// Searching through maps:
 
Map<Integer, String> nums = New.map(1, "one", 2, "two", 3, "three");{"1":"one","2":"two","3":"three"}
 
Find.firstOf(nums).where((k, v) -> k >= 2);{"2":"two"}
 
Find.lastOf(nums).where((k, v) -> v.length() > 4);{"3":"three"}
 
Find.anyOf(nums).where((k, v) -> v.length() == 5);{"3":"three"}
 
Find.allOf(nums).where((k, v) -> k > 1);{"2":"two","3":"three"}
 
Find.in(nums).where((k, v) -> k == 2);true
 
Find.in(nums).where((k, v) -> k > 10);false
// Flow == Java 8 Stream++
 
Set<Character> chars = Flow.chars('a', 'e').toSet();["a","b","c","d","e"]
 
List<Long> nums = Flow.count(1, 7).toList();[1,2,3,4,5,6,7]
 
List<Long> range = Flow.range(1, 7).toList();[1,2,3,4,5,6]
 
Flow.chars('a', 'e').map(c -> c + "!").toList();["a!","b!","c!","d!","e!"]
 
Flow.chars('a', 'd').map(c -> c + "!").map(String::toUpperCase).toList();["A!","B!","C!","D!"]
 
Flow.chars('a', 'c').map(c -> c + "!").filter(s -> !s.startsWith("b")).toList();["a!","c!"]
 
Flow.of("Hi", "there", "X").map(c -> c + "!").filter(s -> s.length() <= 3).toList();["Hi!","X!"]