Questions tagged [vavr]

Questions about the Vavr functional programming library (formerly known as Javaslang).

Vavr (formerly known as Javaslang) is an open-source, functional component library for Java 8+.

Vavr provides immutable collections and the necessary functions and control structures to operate on these values. Most Vavr data structures are purely functional, i.e. they are both immutable and persistent. Operations that appear to modify a purely functional data structure do not alter the underlying data, but instead create a new version (and, in Vavr, a new Java object); references to the old version remain valid.

(For efficiency, persistent data structures are generally implemented so as to share as much state between versions as possible.)

See Also:

154 questions
2
votes
1 answer

Vavr source jar is missing classes

When trying to look up the implementation of certain classes in Vavr, such as Patterns.java, for example, with all its inner classes, i.e. Patterns.$Success, Eclipse is refusing to open them because they are not contained in the source jar…
Simeon Leyzerzon
  • 18,658
  • 9
  • 54
  • 82
2
votes
1 answer

Performing side-effects in Vavr

I'm going through Vavr Usage Guide's section about performing side-effects with Match and other "syntactic sugar" as they call it. Here is the example given there: Match(arg).of( Case($(isIn("-h", "--help")), o -> run(this::displayHelp)), …
Simeon Leyzerzon
  • 18,658
  • 9
  • 54
  • 82
2
votes
1 answer

Stream generator method in vavr

There's a following example in Vavr documentation: // 1000 random numbers for (double random : Stream.gen(Math::random).take(1000)) { ... } However, I cannot find the above method (gen) on Stream type in vavr javadoc. These seem to be similar…
Simeon Leyzerzon
  • 18,658
  • 9
  • 54
  • 82
2
votes
1 answer

Vavr property testing

Property checking feature is advertised in the latest Vavr documentation along with the following example of its usage: Arbitrary ints = Arbitrary.integer(); // square(int) >= 0: OK, passed 1000 tests. Property.def("square(int) >= 0") …
Simeon Leyzerzon
  • 18,658
  • 9
  • 54
  • 82
2
votes
2 answers

How does io.vavr.control.Validation work in these examples?

I'm having some trouble understanding the validation library, io.vavr.control.Validation. At the risk of asking too broad a question, I do have several sub-questions—however I believe they are closely related and would piece together to help me…
Andrew Cheong
  • 29,362
  • 15
  • 90
  • 145
2
votes
2 answers

Devide a range into x number of ranges

I have been breaking my head over this I want to create a list of intervals (as Tuple2 instances) of a range between min and max divided in numberOfIntervals. This particular project is in java (no scala allowed), so i am using vavr, but any scala…
jen
  • 357
  • 2
  • 10
2
votes
1 answer

How to cache an instrumented class with an instance forwarder?

The use case is to implement a dirty field tracker. For this I have an interface: public interface Dirtyable { String ID = "dirty"; Set getDirty(); static T wrap(final T delegate) { return…
Xavier Arias
  • 162
  • 2
  • 10
2
votes
1 answer

Javaslang - running a method in Pattern Matcher

I'm trying to incorporate javaslang's pattern matching in a classic factory pattern: public void log(String message, Integer level) { Match(level).of( Case($(INFO), run(() -> logger.info(message))), // …
fbielejec
  • 3,492
  • 4
  • 27
  • 35
1
vote
1 answer

How to chain vavr's Either nicely?

I have a function returning an Either (function2) , which result depends on another function returning another Either (function1) Both functions rely on a Try block that could fail, and I want to compose…
Simon E.
  • 23
  • 4
1
vote
1 answer

Java Vavr pattern matching on tuple using wild card

I'm using Vavr to do pattern matching on a vavr-tuple but I can't seem to do get the pattern matching to work in tuple. Here is my code Tuple2 test = Tuple.of("foo", "bar"); Match(test) .of( Case($(API.Tuple("foo",$())), "baz") …
1
vote
0 answers

Nested Mono in Either

I have a method to register a user: public Mono > registerUser(RegisterUserDTO dto) { Mono > > result = userFactory .create(dto.username(), dto.password(), UserRole.COMMON) …
Sampeteq
  • 123
  • 8
1
vote
3 answers

Transform list of Either into list of left and list of right

Vavr's Either seems to solve one of my problems were some method does a lot of checks and returns either CalculationError or CalculationResult. Either calculate (CalculationData calculationData) { // either…
DDT
  • 133
  • 5
1
vote
2 answers

What's the difference between peekOption and headOption in Vavr Collection

Here the doc for Vavr List peekOption https://www.javadoc.io/doc/io.vavr/vavr/0.10.1/io/vavr/collection/List.html#peekOption-- Here the doc of Vavr Traversable…
Zbooby
  • 9
  • 2
1
vote
1 answer

Writing readable code using vavr Either in Kotlin while performing sequential operations

I have following piece of code written in Kotlin using vavr. The function performs a chain of operations one by one and if one of them fails, it returns Error. If all operations succeed, it returns SuccessObject. Left is assumed to be error and…
Varun Singh
  • 1,135
  • 13
  • 18
1
vote
1 answer

Validating an object with a long list of predicates

I have an object, Bill, with a number of fields. In the method below, I get the bill with a function. I want to validate it with a list of Predicate, which are paired with the appropriate error message to be applied if the predicate test…
FaraBara
  • 115
  • 7