Skip to content

Commit dca2b0c

Browse files
feat(result): Added isError & isOk
1 parent 0496e89 commit dca2b0c

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

src/main/java/gentle/Result.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,28 @@ default Optional<T> asOptional() {
4545
};
4646
}
4747

48+
/**
49+
* Returns whether this {@code Result} represents an error.
50+
* <p>
51+
* Equivalent to checking {@code instanceOf Err}.
52+
*
53+
* @return {@code true} if this is an {@link Err}, otherwise {@code false}
54+
*/
55+
default boolean isError() {
56+
return this instanceof Err<T,E>;
57+
}
58+
59+
/**
60+
* Returns whether this {@code Result} represents a successful value.
61+
* <p>
62+
* Equivalent to checking {@code instanceOf Ok}.
63+
*
64+
* @return {@code true} if this is an {@link Ok}, otherwise {@code false}
65+
*/
66+
default boolean isOk() {
67+
return this instanceof Ok<T,E>;
68+
}
69+
4870
/**
4971
* Transforms the success value using the given function, leaving errors unchanged.
5072
*

0 commit comments

Comments
 (0)