File tree Expand file tree Collapse file tree 1 file changed +38
-0
lines changed
Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change 1+ package com .redomar .game .lib ;
2+
3+ import org .jetbrains .annotations .Contract ;
4+ import org .jetbrains .annotations .NotNull ;
5+
6+ import java .util .Optional ;
7+
8+ public class Either <L , R > {
9+ private final Optional <L > left ;
10+ private final Optional <R > right ;
11+
12+ private Either (final Optional <L > left , final Optional <R > right ) {
13+ this .left = left ;
14+ this .right = right ;
15+ }
16+
17+ @ Contract ("_ -> new" )
18+ static <L , R > @ NotNull Either <L , R > left (final L value ) {
19+ return new Either <>(Optional .of (value ), Optional .empty ());
20+ }
21+
22+ @ Contract ("_ -> new" )
23+ static <L , R > @ NotNull Either <L , R > right (final R value ) {
24+ return new Either <>(Optional .empty (), Optional .of (value ));
25+ }
26+
27+ boolean isLeft () {
28+ return left .isPresent ();
29+ }
30+
31+ L getLeft () {
32+ return left .get ();
33+ }
34+
35+ R getRight () {
36+ return right .get ();
37+ }
38+ }
You can’t perform that action at this time.
0 commit comments