Skip to content

Commit cc4171c

Browse files
refactor: Make Result/Option new* return the base class
This is so that it is different to the plain old constructor.
1 parent 2cd7169 commit cc4171c

3 files changed

Lines changed: 8 additions & 8 deletions

File tree

src/main/java/net/marcellperger/mathexpr/util/rs/Option.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,14 @@ record None<T>() implements Option<T> {
3535
}
3636
}
3737

38+
// Same as new Some/None but return Option
3839
@Contract("_ -> new")
39-
static <T> @NotNull Some<T> newSome(T value) {
40+
static <T> @NotNull Option<T> newSome(T value) {
4041
return new Some<>(value);
4142
}
4243

4344
@Contract(" -> new")
44-
static <T> @NotNull None<T> newNone() {
45+
static <T> @NotNull Option<T> newNone() {
4546
return new None<>();
4647
}
4748

src/main/java/net/marcellperger/mathexpr/util/rs/Result.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,11 @@ public String toString() {
4343
}
4444
}
4545

46-
static <T, E> Ok<T, E> newOk(T value) {
46+
// same as new Ok/Err but return Option
47+
static <T, E> Result<T, E> newOk(T value) {
4748
return new Ok<>(value);
4849
}
49-
static <T, E> Err<T, E> newErr(E err) {
50+
static <T, E> Result<T, E> newErr(E err) {
5051
return new Err<>(err);
5152
}
5253

src/test/java/net/marcellperger/mathexpr/util/rs/OptionTest.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package net.marcellperger.mathexpr.util.rs;
22

33
import net.marcellperger.mathexpr.MiniMock.*;
4-
import net.marcellperger.mathexpr.util.rs.Option.Some;
5-
import net.marcellperger.mathexpr.util.rs.Option.None;
64
import org.junit.jupiter.api.Test;
75

86
import java.util.ArrayList;
@@ -12,10 +10,10 @@
1210
import static org.junit.jupiter.api.Assertions.*;
1311

1412
class OptionTest {
15-
Some<Integer> getSome() {
13+
Option<Integer> getSome() {
1614
return Option.newSome(314);
1715
}
18-
None<Integer> getNone() {
16+
Option<Integer> getNone() {
1917
return Option.newNone();
2018
}
2119

0 commit comments

Comments
 (0)