HappyPath<Happy, Sad> happyAttempt(Attempt<Happy>)

TODO: this is just a generated example

javadoc usage tests

Added in version 2.5.0

Happy attempt can fail

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.

Happy attempt can introduce sad type via then

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.