jabrena / exceptions-in-java

Apache License 2.0
0 stars 0 forks source link

Read more about Either from VAVR #27

Closed jabrena closed 1 month ago

jabrena commented 1 month ago
jabrena commented 1 month ago
jabrena commented 1 month ago

private List getBuildsForSpecificRepos(Collection repositories) { return repositories.parallelStream() .map(this::fetchBuilds) .filter(Either::isLeft) .map(Either::getLeft) .flatMap(item -> item.getBuilds().stream()) .collect(Collectors.toList()); }

jabrena commented 1 month ago

public Either<String, Integer> properFlatMapOfEither(String age) { Either<String, String> outerEither = Option .of(age) .map(Either::<String, String>right) .getOrElse(Either.left("empty"));

Either<String, Integer> flattened = outerEither
  .flatMap(e -> eitherWrapper(e));

return flattened;

}

jabrena commented 1 month ago

private Either<ContractViolation, Tuple2<Section, Constraint>> findSectionInDocument( SectionConstraint sectionConstraint) { return sections().stream() .filter(sectionConstraint::matches) .map(section -> Tuple.of(section, sectionConstraint.getConstraint())) .findAny() .map(Either::<ContractViolation, Tuple2<Section, Constraint>>right) .orElseGet(() -> Either.left(missingSectionViolation(sectionConstraint))); }