Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
The last minor release before 1.0.0
Release Details
A new powerful collection library saves us from source.stream().really("?").collect(sink()) pipelines.
List<String> names = persons
.filter(p -> p.age > 12)
.map(Person::getName);
The functional For is an expression that yields a value. The result is a lazy evaluated collection of elements.
Iterator<String> iterator =
For(persons.filter(Person::hasAddress), p ->
For(p.addresses).yield(a ->
p.name + "," + a.street
)
);
Vavr and Java are fully interoperable.
java.util.List<Integer> result =
iterator.map(String::length).asJava();
Structural pattern matching is an easy way to decompose values. The result is ... a value!
Number num = Match(personOption).of(
Case($Some($Person($())), person -> 1.0d),
Case($None(), 0)
);
The Try monad represents the result state of a computation which may be a Success or a Failure.
R result = Try(() -> mightFail())
.recover(x -> ...)
.getOrElse(defaultValue);
Java's Optional is not Serializable. We use Vavr's Option for remote operations. Check out our JSON module!
class Person implements Serializable {
final Option<String> title;
final String name;
...
}
Vavr core is a functional library for Java. It helps to reduce the amount of code and to increase the robustness. A first step towards functional programming is to start thinking in immutable values. Vavr provides immutable collections and the necessary functions and control structures to operate on these values. The results are beautiful and just work.
There are several additional modules that group around Vavr's core. All of these are supported by the Vavr open source organization.