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
0
votes
2 answers

Vavr - turn List of Lists into single List

I've got two vavr Lists: List list1 = List.of("one", "two", "three", "for"); List list2 = List.of("one", "two", List.of("three", "for")); How can I transform the list2 to be equal to the list1? EDIT I try to explain more what I want…
kojot
  • 1,634
  • 2
  • 16
  • 32
0
votes
1 answer

JSON Validation fails at runtime, even though tests pass

I am using popular JSON schema library - json-schema-validator - for checking incoming payloads against a schema of my own. The following is summary of my grief: private final JsonSchemaFactory factory = JsonSchemaFactory.byDefault(); private…
Nirmalya
  • 717
  • 9
  • 19
0
votes
2 answers

Combining multiple `Try` instances of different result types as applicatives

Is there an api for combining Try instances in Vavr that is similar to the way the Scalaz applicative operator |@| works? Specifically, if I have more than two Try instances, for example, Try, Try and Try, I would like to combine these…
divesh premdeep
  • 1,070
  • 3
  • 16
  • 28
0
votes
0 answers

How to convert a form field to Vavr Option in Spring controller

I have a class Outcome, one of whose fields is an instance of Schema. But because the latter might be null, I have defined Outcome's getSchema() to return the value wrapped in Vavr's Option. In my Spring Boot 2 application the controller method that…
Hamish Lawson
  • 540
  • 1
  • 3
  • 7
0
votes
1 answer

Named parameters feature in Vavr

Vavr User Guide refers to the following piece of code while discussing its named parameters feature: Named Parameters Vavr leverages lambdas to provide named parameters for matched values. Number plusOne = Match(obj).of( …
Simeon Leyzerzon
  • 18,658
  • 9
  • 54
  • 82
0
votes
1 answer

Memoization with Vavr seems incosistent

When the function is defined as following static Function1 fibonacci = Function((BigInteger value) -> value.equals(BigInteger.ZERO) ? BigInteger.ZERO : value.equals(BigInteger.ONE) ?…
ozgur
  • 2,549
  • 4
  • 25
  • 40
0
votes
0 answers

Use Vavr pattern matching to convert Option to Try, failing for unrecognized values

Say I have two interfaces, A and B. A has three known implementations, A1, A2, and A3; B has three corresponding concrete wrapper classes, B1, B2, and B3, such that the constructor of B1 takes an A1, B2 takes an A2, and so on. I have a method that…
David Moles
  • 48,006
  • 27
  • 136
  • 235
0
votes
1 answer

retrieving vavr collection via spring data rest from mongo db doesn't work

I created a small spring boot project to retrieve a sample object from mongoDb via spring data rest which contains a Seq (vavr collection). Immediately after booting the app it doesn't work. At first I have to do an insertion and afterwards it works…
RenneB
  • 41
  • 5
0
votes
1 answer

Generating tuples containing Long for Vavr Property Checking

I need a pair of random longs for property checking with Vavr. My implementation looks like this: Gen longs = Gen.choose(Long.MIN_VALUE, Long.MAX_VALUE); Arbitrary> pairOfLongs = longs .flatMap(value -> random ->…
MariuszS
  • 30,646
  • 12
  • 114
  • 155
0
votes
1 answer

Eclipse flags (working) code as compilation error and will not run

I have some fairly complex code that uses Javaslang. If I compile it into a jar, it runs fine. However, when I try to step into it in Eclipse for debugging, Eclipse flags it as a compilation error and dies when it reaches that line. The…
betseyb
  • 1,302
  • 2
  • 18
  • 37
0
votes
2 answers

How to throw when stream of javaslang Try contains an exception

In javaslang, if I have a Stream, how can I throw when any of the items on the stream contains a checked Exception? I cannot do this because peek does not accept a throwing lambda stream.peek(t -> t.onFailure((t2) -> {throw…
Daniel Pinyol
  • 2,094
  • 2
  • 15
  • 15
0
votes
1 answer

Why is javaslang CharSeq final?

We're all familiar with the argument about why String is final in java. However, I was wondering why javaslang's CharSeq is final too. Given javaslang's FP inspirations and the fact that Haskell allows type synonyms, I would have thought this would…
James Burton
  • 132
  • 9
-1
votes
1 answer

Why won't vavr's Function1 accepting Seq class accept Seq?

I'm using Java with vavr and I have a Function1 that accepts a Seq and returns a String. Why won't that class accept Seq? It seems like something with contravariance/covariance/invariance, but I am having trouble working through why…
Jon Gunter
  • 1,864
  • 2
  • 15
  • 21
-1
votes
2 answers

Does Declarative Style fail if there are multiple intermittent breaks/returns?

The below code is intuitive in imperative style. Does trying to do the same in declarative style makes it more complex? for (var entry : map.entrySet()) { if (entry.getKey().length() > 10) { return "invalid_key"; } else if…
Gopal S Akshintala
  • 1,933
  • 1
  • 17
  • 24
-1
votes
1 answer

Changing Java Map code to VAVR (javaslang)

I have 2 methods involving Map in plain Java and my task is to change them to full VAVR. The problem for now is that I get java.lang.ClassCastException: class java.util.HashMap cannot be cast to class io.vavr.collection.Map (java.util.HashMap is in…
wojciechw
  • 71
  • 1
  • 13
1 2 3
10
11