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
1 answer

How to check performance of switch and vavr's match?

I am intrested how does exacly switch vs vavr's match performance seems, what is the easiest wy to check it? @edit I checked it, it seems like vavr's switch is like 2x slower than regular java switch
Shirabu
  • 99
  • 1
  • 4
1
vote
1 answer

Try in Vavr with method reference

I am using io.vavr.control.Try and try to do Try.run but I can't use method reference with parameter. How can I fix this? PingRequest pingRequest = new PingRequest(); PingCall pingCall = this.client.newPingCall(); //Try attempt =…
DD Jin
  • 355
  • 1
  • 3
  • 15
1
vote
1 answer

If (not null && not null) Java functional programming

Before Java 8, i got used to writte my code this way import io.vavr.control.Option; Option nullableValueA=Option.of("toto"); Option nullableValueB=Option.of(null); if (nullableValueA.isEmpty() && nullableValueB.isEmpty()){ …
jdhalleine
  • 13
  • 1
  • 3
1
vote
1 answer

Try waiting for a CompletableFuture

Is there a way of trying to wait for a CompletableFuture a certain amount of time before giving a different result back without cancelling the future after timing out? I have a service (let's call it expensiveService) that runs off to do its own…
Druckles
  • 3,161
  • 2
  • 41
  • 65
1
vote
2 answers

How to not write Option.None with jackson objectMapper (and read it)?

I use jackson ObjectMapper to serialize and deserialize some data of mine, which have fields of javaslang Option type. I use JavaslangModule (and Jdk8Module). And when it write the json, Option.None value fields are written as null. To reduce the…
Juh_
  • 14,628
  • 8
  • 59
  • 92
1
vote
1 answer

Incompatible types while returning Either

I'm using vavr's Either to control flow of my application and it worked fine, until I didn't have to mix few domains... First of all, I got one interface that is shared between domains. public interface DomainError { String getCause(); } And…
Weeedooo
  • 501
  • 8
  • 25
1
vote
2 answers

How to throw custom exception from resilience4j TimeLimitter?

I am using resilience4j's TimeLimiter to control timeout requests for a RestTemplate call. I am throwing a custom exception if the response.getBody() is null but, resilience4j's always throwing exception provided in getorElseThrow. how can I throw a…
1
vote
1 answer

Get regular expression groups with Vavr

Considering that Vavr provides tuples, is it possible to use them for capturing groups in regular expressions? Taking an HTTP request line as an example string to match GET /resource HTTP 1.1 and a matching pattern Pattern.compile("(\\w+) (.+)…
Matthias Braun
  • 32,039
  • 22
  • 142
  • 171
1
vote
2 answers

Pattern Matching matches all the Case condition

I am new vavr so I don't know if I am missing some basic stuff but i am doing pattern matching which Java does not have right now. After debugging I realized that vavr matches all the Cases but will not execute the value if a Supplier is provided if…
Sachin Jain
  • 97
  • 1
  • 10
1
vote
2 answers

Pattern matching object decomposition on list in Vavr

Is there any option to apply object decomposition on vavrs collections? I.e. something like this code snippet from scala: val x = List(1, 2, 3) val t = x match { case List(a, b, c) => (a, b, c) } (in this example we're converting list to…
IgorekPotworek
  • 1,317
  • 13
  • 33
1
vote
1 answer

Express "success" or "throw exception" of Vavr Try in Java unit test

I have a simple unit test which asserts on an object instance of Try from the vavr library. @Test public void testFoo() { final Try result = createMyFooInstance(); assertThat(result.isSuccess()).isTrue(); } My question focuses on the…
Emdee
  • 1,689
  • 5
  • 22
  • 35
1
vote
1 answer

Unbox value from Either vavr

Background I have a small function that can return Either. If it succeed it returns a float otherwise an error string. My objective is to perform a series of operations in a pipeline, and to achieve railway oriented programming using…
Flame_Phoenix
  • 16,489
  • 37
  • 131
  • 266
1
vote
1 answer

How to properly implement this using Vavr?

I would like got your advise on how to properly write this code on a functional way: private Option calculate(Integer X, Integer Y) { if (X < Y) return Option.none(); return Option.of( X + Y ); } public Option
1
vote
1 answer

Jackson - @JsonCreator return generics

I want to integrate vavr validation library in my command dto's in a way that when command dto is deserialized from request, return type of the static factory will be Try but jackson is throwing following error : Type definition error: [simple…
user3018350
1
vote
2 answers

Is there a better way to log failures in a chain of Java Vavr Try clauses?

I'm trying to log at each failure stage and, as far as I can tell, I need to nest the try and log inside a flatmap. Try.of(() -> true). onFailure(h -> System.out.println("first onFailure")). flatMap(i -> Try.of(() -> { throw new…
Richard Polton
  • 101
  • 1
  • 5