diff --git a/src/main/java/edu/kit/typicalc/util/Result.java b/src/main/java/edu/kit/typicalc/util/Result.java index bd52e03..2bb939a 100644 --- a/src/main/java/edu/kit/typicalc/util/Result.java +++ b/src/main/java/edu/kit/typicalc/util/Result.java @@ -71,13 +71,19 @@ public class Result { * @return the value * @throws IllegalStateException if this is an error */ - public T unwrap() { + public T unwrap() throws IllegalStateException { if (value == null) { throw new IllegalStateException("tried to unwrap a result, but error = " + error); } return value; } + /** + * If the result contains a regular value, returns that value. + * Otherwise return the supplied alternative value. + * + * @return the value or the alternative + */ public T unwrapOr(T alternative) { if (value == null) { return alternative; @@ -99,6 +105,13 @@ public class Result { return error; } + /** + * Apply a function to the value of this result if it exists. + * + * @param mapping function to apply + * @param new type of the value + * @return new result + */ public Result map(Function mapping) { return new Result<>(value != null ? mapping.apply(value) : null, error); }