vavr-io / vavr

vʌvr (formerly called Javaslang) is a non-commercial, non-profit object-functional library that runs with Java 8+. It aims to reduce the lines of code and increase code quality.
https://vavr.io
Other
5.59k stars 620 forks source link

Propose Validation.all() to combine multiple validations on the same value. #2735

Closed evantill closed 1 year ago

evantill commented 1 year ago

Hello all,

I'm submitting this pull request to add a method to combine multiple validation of the same type into a single validation.

I've added the tests and it's working as expected. I've also updated the relevant documentation to reflect the changes. Please let me know if there's anything that needs to be changed or improved upon. I'm happy to make any necessary updates before merging. Thank you for your time!

Example:

We have a Path and we want to validate that it’s an absolute path on a writable directory. We already have simple validations like :

Validation<String,Path> isAbsolute(Path)
Validation<String,Path> isDirectory(Path)
Validation<String,Path> isWritable(Path)

We can then combine those like this :

var pathValidation=Validation.all(
    isAbsolute(path),
    isDirectory(path),
    isWritable(path)
);
evantill commented 1 year ago

Hi, any update on this PR please ? You can close it if you are not interested by merging it