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

vavr return from loop if condition fails

I am writing a code to validate category using vavr private static Validation> isCategoryValid( List categories) { java.util.List categoryList = new ArrayList<>(); for…
raaeusagvc
  • 71
  • 6
1
vote
1 answer

Data validation and account creation with Either - how to write it better?

I have an AccountCreator class with a create method that takes a DTO with the data needed to create an account. At the beginning there is an attempt to create 2 value objects (UserName and Password), then validate the uniqueness of the user name,…
Sampeteq
  • 123
  • 8
1
vote
1 answer

Use Vavr list in Mapstruct - java: No implementation type is registered for return type io.vavr.collection.List

I am trying to use Mapstruct on an object which has Vavr list. But I get the error java: No implementation type is registered for return type io.vavr.collection.List but works fine on java.util.List I see another question few years back about "Page"…
firstpostcommenter
  • 2,328
  • 4
  • 30
  • 59
1
vote
1 answer

Serialize and Deserialize Java object having vavr list

I have a Java object with vavr list. @Value @Builder(toBuilder = true) public class Customer { private final List remarks; } When I serialize the object objectwriter.writeValueAsString(currentDossier) and print the values then in the…
firstpostcommenter
  • 2,328
  • 4
  • 30
  • 59
1
vote
2 answers

Vavr - append 2 Lists of type io.vavr.collection.List into a single List based on the fields

I have the below requirement, I have 2 Lists, one is EmployeeList and DepartmentList now I want to merge/append the 2 lists into another List(finalList) based on the fields in the example below. List list = List.of( new…
user3190018
  • 890
  • 13
  • 26
1
vote
1 answer

Vavr Try.filter NoSuchElementException

@Value.Immutable interface TestCliConfiguration extends CliConfiguration { default Path getConfigDir() { return Try.ofSupplier( this::getClass ) .map( Class::getClassLoader ) .map( cl -> cl.getResource( "config" ) ) .filter(…
xenoterracide
  • 16,274
  • 24
  • 118
  • 243
1
vote
2 answers

Are VAVR collections really persistent

I understand persistent in this context to mean preserving previous versions of a collection upon an attempt to modify it: List l = List.of(1, 2, 3); List l2 = l.append(4); However, if I lose the reference l to the original…
Andy Cribbens
  • 1,370
  • 2
  • 11
  • 22
1
vote
1 answer

Coerce type without creating temporary variable

I have the following function: Map> convert(Map> input) { return HashMap.empty(); } I am calling it in the following way: Map> stringMap =…
Anmol Singh Jaggi
  • 8,376
  • 4
  • 36
  • 77
1
vote
1 answer

Fold either to return different value

I have a Vavr Either that looks like this: Either maybePendingPayment = ... I want to fold this response to return Either return maybePendingPayment.fold(domainError -> domainError, pendingPayment ?…
coconut
  • 1,074
  • 4
  • 12
  • 30
1
vote
1 answer

Unexpected return type of vavr's Either in reactor

There are two simple methods using vavr's Either. public Either testEither(int s) { if (s == 0) return Either.left("Wrong"); return Either.right(s); } public Mono> testReactorEither(int s) { …
Tonny Tc
  • 852
  • 1
  • 12
  • 37
1
vote
2 answers

How to throw exception when Try.of() fails?

I want to throw Exceptions that are extended from Exception if Try.ofCallable() fails. I have a callable of the type: final Callable decoratedCallable = circuitBreakerService.getDecoratedMethod( myArg1, () ->…
Saif
  • 2,530
  • 3
  • 27
  • 45
1
vote
1 answer

What is an idiomatic way to use AtomicReference while using a Map in vavr?

This is more of a question that inquires what is the approach preferred by seasoned hands in Stack OverFlow community. I want to learn about that because I don't want to write unnecessary boilerplate code. So, treat my Q as that of a newbie's. My…
Nirmalya
  • 717
  • 9
  • 19
1
vote
1 answer

Deserialization error after fetching vavr Multimap using RestTemplae

I'm trying to deserialize Jackson Multimap //given val newUser = NewUserDTO(ALREADY_TAKEN_USERNAME, ALREADY_TAKEN_EMAIL,"qddqwdW221QZ&^$!") //when val response = restTemplate.exchange("http://localhost:${port}/user",…
1
vote
2 answers

Chaining functions that return Vavr Either

I have a series of functions that take in a Request object and return a Vavr Either. The Either will contain a Result object if the task is complete or a modified Request object if the task needs to be completed by another function. The thought was…
zkello
  • 239
  • 2
  • 15
1
vote
1 answer

Handling exceptions idiomatically with VAVR

Having spat the Google Guava kool-aid back out of our mouths, and diving head-first into our new infatuation with VAVR and its sparkling ideals, say we are map()ping a Stream, performing foldLeft() on a Traversable, or similar, and one of the inner…
Vivid Inc.
  • 55
  • 8