TODO: this is just a generated example
Added in version 2.5.0
RuntimeException technicalFailure = new RuntimeException();
Attempt<Happy> attempt = () -> {throw technicalFailure;};
HappyPath<Happy, Sad> happyPath = HappyPath.happyAttempt(attempt);
assertThat(happyPath.getTechnicalFailure()).isEqualTo(technicalFailure);
An attempt can fail and turn into a technical failure.
Sad sad = new Sad();
HappyPath<Happy, Sad> happyPath = HappyPath.<Happy, Sad>happyAttempt(Happy::new)
.then(happy -> HappyPath.sadPath(sad));
assertThat(happyPath.getSad()).isEqualTo(sad);
An attempt that was once happy can be turned into a sad path.
The happyAttempt method is playing the role of the Try monad here, but is lifted into the Either monad immediately, which is why the Sad type has to be specified up front.