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
1
vote
2 answers

Is it possible to use the map interface with io.vavr.collection.HashMap?

Whilst trying to use Vavr's immutable map (io.vavr.collection.HashMap) with the java.util.Map interface, I did not manage to get the code to compile - at least not by using the .of() static method in io.vavr.collection.HashMap. In essence this is…
gil.fernandes
  • 12,978
  • 5
  • 63
  • 76
1
vote
1 answer

vavr's Future don't execute some code, with method andThen

In this code, I have two methods using vavr library. From this library I am using Future with the method andThen, this method run when the future has been completed, and this is synchronous, but when the thread call to the method "printTime" in this…
1
vote
1 answer

Java Vavr : Log Exception on Failure

I want to log exceptions while using VAVR (formerly javaslang). Below is the sample code snippet. //will get 500 as response from this url String sampleurl = "http://someurl.com"; List myList = List.of(sampleurl); …
Jai
  • 369
  • 3
  • 16
1
vote
4 answers

Concise way to reduce where one of the states throws an exception

I have a bunch of these: Validation a; Validation b; Validation c; Here are some of their methods: boolean isValid(); boolean isInvalid(); // === !isValid() String getError(); Now, I was trying to do…
Andrew Cheong
  • 29,362
  • 15
  • 90
  • 145
1
vote
1 answer

Using local Vavr immutable collections inside a Java 8 lambda

Given the code fragment below, how would I use Vavr immutable lists or streams? I can't as a local variable since there is no way to mark it final. I don't want to promote List points to a class member. import…
hyiger
  • 37
  • 6
1
vote
3 answers

Functional programming idiom for applying a series of void functions to a single value

Given a value foo and a Stream of Consumer void functions, what's the most concise way to apply each function to the value? Right now I have consumers.forEach(c -> c.accept(foo)); which isn't terrible, but I suspect there might be some way to…
David Moles
  • 48,006
  • 27
  • 136
  • 235
1
vote
1 answer

Walk a chain of objects recursively in functional style

A common looping pattern in imperative coding styles is to follow a chain of objects to find the end, e.g.: private ThreadGroup rootOf(ThreadGroup leaf) { ThreadGroup rootGroup = leaf; ThreadGroup parentGroup; while ((parentGroup =…
David Moles
  • 48,006
  • 27
  • 136
  • 235
1
vote
1 answer

Javac can't infer type unless lambda expression is inlined

I have the following snippet of Java code using Vavr. Type-checking fails unless I inline a parameter. Why can the code below not be accepted by the compiler? import io.vavr.Function1; import io.vavr.Tuple; import io.vavr.Tuple2; import…
Zaaier
  • 685
  • 8
  • 22
1
vote
0 answers

Javaslang Option.nothing()

Recently I started reading about Javaslang and its improvements to the classes added by Java 8. Diving into the documentation I came across the following method: Option.nothing() Which returns an instance of a singleton of type Option. I…
Adrian Jałoszewski
  • 1,695
  • 3
  • 17
  • 33
1
vote
2 answers

How to find WebElement in a List by text?

I want to find WebElement in a List by text. My method has such arguments: List webElements, String text. For matching text I prefer to use javaslang library. So, what we have: protected WebElement…
Oleksii
  • 1,623
  • 20
  • 26
1
vote
1 answer

Extract keys and left values from a Map in Javaslang

Given a Map, what's the most straightforward way to convert it to a Map containing only the entries with boolean values? Right now I have this: Map boolMap = eitherMap …
David Moles
  • 48,006
  • 27
  • 136
  • 235
1
vote
1 answer

javaslang List.of() on cdi Instance

I have multiple class with a Qualifier that I created: @ServiceComponent(restPath = "/trucks") public class TruckService { } @ServiceComponent(restPath = "/cars") public class CarService { } here is the Qualifier (not important for the…
Cedric Dumont
  • 1,009
  • 17
  • 38
0
votes
1 answer

Either flatmap type mix-up in Vavr

Sample available here: https://github.com/codependent/hexapp-java/blob/vavr/src/main/java/com/codependent/hexapp/application/port/in/impl/CreateDepartmentUseCaseImpl.java I have chained Either operations that require the usage of Either.flatmap: …
codependent
  • 23,193
  • 31
  • 166
  • 308
0
votes
1 answer

vavr Either sequence of processing steps

java 19 vavr (latest) I would like to create a processing flow of steps (processing XML file) that can split the flow to sub-processing steps. Each step can fail so I wrap it in an Either (vavr) to control the flow. load XML file (from cloud…
Gadi
  • 1,539
  • 22
  • 37
0
votes
2 answers

Problem with Either and errors types incompatibility

I have a problem with Either errors types incompatibility. A method to create Account entity: static Either create( String userNameCandidate, UserNameUniquenessValidator userNameUniquenessValidator, String…
Sampeteq
  • 123
  • 8