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

Why this converter needs casting?

I need to implement an enum to enum converter in java: Enum_2 > Enum_1 and I'd like to do it in generic way. So I defined an interface: interface LabelAware { String getLabel(); T getObject(); } and Enum_1: enum Enum_1 { …
Opal
  • 81,889
  • 28
  • 189
  • 210
10
votes
1 answer

Combining Either's in Vavr?

I have a couple of Vavr Either's and I want to invoke a function with the Right value for each of these Either's. For example: Either either1 = .. Either either2 = .. Either either3 =…
Johan
  • 37,479
  • 32
  • 149
  • 237
9
votes
3 answers

Serializer/Deserializer for Vavr objects

Hello Im trying to add vavr to my projet, right now Im struggling with proper serializaition of Vavr.List objects. Below is my controller: import io.vavr.collection.List; @GetMapping(value = "/xxx") public List getFile() { …
filemonczyk
  • 1,613
  • 5
  • 26
  • 47
8
votes
7 answers

Java Functional Programming: How to convert a if-else ladder inside for loop to functional style?

The expectation is derive 3 lists itemIsBoth, aItems, bItems from the input list items. How to convert code like below to functional style? (I understand this code is clear enough in an imperative style, but I want to know does declarative style…
8
votes
1 answer

What is the need for an Immutable Queue?

I have been working with Java for several years now. Recently came across Vavr, a functional library for Java, that provides immutable collection API. I am curious to know the reason for having an immutable Queue. My understanding is that a Queue…
Naresh Babu
  • 702
  • 1
  • 7
  • 17
8
votes
3 answers

How to implement this nested flow with optionals?

I've have a method that takes String as an input and should also return a String. The following ASCII art presents the logical flow: Option optA = finder.findA(input); optA /\ isEmpty() / \ isDefined() / \ …
Opal
  • 81,889
  • 28
  • 189
  • 210
7
votes
3 answers

Vavr with generics gives incompatible types

Could anyone please explain why this code: interface Lol { default Try> lol() { return Try.of(List::empty); } } class LolImpl implements Lol { @Override public Try> lol() { return Try …
Opal
  • 81,889
  • 28
  • 189
  • 210
7
votes
2 answers

javaslang List of Tuples2 to Map transormation

What is the most idiomatic way to transform a Stream> into a Map> with javaslang 2.1.0-alpha? // initial stream Stream.of( Tuple.of("foo", "x"), Tuple.of("foo", "y"), Tuple.of("bar",…
Ghiro
  • 500
  • 1
  • 4
  • 11
6
votes
1 answer

javaslang/Vavr : How to do a try with resource

Here is my code snippet : public static void main(String[] args) { Try.of(Main::getLines) .onFailure(cause -> log.error("An error has occurred while parsing the file", cause)); } private static List getLines() { return…
Saïd R.
  • 61
  • 1
  • 3
6
votes
5 answers

How to flip an Option> to a Try>

I have an Try>. I want to flatMap Foo into a Bar, using it using an operation that can fail. It's not a failure if my Option is an Option.none(), (and the Try was a success) and in this case there's nothing to do. So I have code…
durron597
  • 31,968
  • 17
  • 99
  • 158
6
votes
3 answers

Converting an Array to Javaslang Map with counts for each type

I am currently looking at Javaslang library and I am trying to convert some of my code to Javaslang. I currently have this bit of code which is all pure Java Cell[][] maze; //from input Map cellCounts = Stream.of(maze) …
Ash
  • 2,562
  • 11
  • 31
6
votes
1 answer

Javaslang object decomposition not working

I am using Javaslang-2.1.0-alpha and its Javaslang-match equivalent to do some object decomposition. According to this by blog post by Daniel in the "Match the Fancy way" section: Match(person).of( Case(Person("Carl", Address($(), $())), (street,…
egimaben
  • 653
  • 7
  • 22
5
votes
1 answer

Fix left side in Either of Java Vavr

I want to avoid: Either processEmployee(Employee e) and use: Result processEmployee(Employee e) where left is fixed: Result extends Either Is there an example of this? When I try this nothing compiles for…
jakstack
  • 2,143
  • 3
  • 20
  • 37
5
votes
2 answers

How to return Either a void or a String with vavr

I'm have a function which should return nothing (void ) or a String when some conditions are not met. I try this line Either.left(Void) private Either processOrReturnErrorMessage(){ //Do something and in some case return a…
EFOE
  • 609
  • 1
  • 10
  • 20
5
votes
4 answers

Filter objects from a list that have the same member

I have a list of objects. The object looks like this: public class Slots { String slotType; Visits visit; } public class Visits { private long visitCode; private String agendaCode; private String scheduledTime; private String…
coconut
  • 1,074
  • 4
  • 12
  • 30
1
2 3
10 11