This repository has been archived by the owner on Aug 9, 2024. It is now read-only.
generated from microsoft/vscode-remote-try-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
53 additions
and
6 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
...tructuraDatos/pry3/Collections/Tuple.java → ...raDatos/pry3/utils/Collections/Tuple.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ructuraDatos/pry3/Collections/Tuple1.java → ...aDatos/pry3/utils/Collections/Tuple1.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ructuraDatos/pry3/Collections/Tuple2.java → ...aDatos/pry3/utils/Collections/Tuple2.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ructuraDatos/pry3/Collections/Tuple3.java → ...aDatos/pry3/utils/Collections/Tuple3.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ructuraDatos/pry3/Collections/Tuple4.java → ...aDatos/pry3/utils/Collections/Tuple4.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ructuraDatos/pry3/Collections/Tuple5.java → ...aDatos/pry3/utils/Collections/Tuple5.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
src/main/java/com/utp/clsEstructuraDatos/pry3/utils/Either.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.utp.clsEstructuraDatos.pry3.utils; | ||
|
||
import java.util.Optional; | ||
|
||
public class Either<T, E> { | ||
|
||
private Optional<T> left; | ||
private Optional<E> right; | ||
|
||
private Either(T value, E error) { | ||
this.left = Optional.ofNullable(value); | ||
this.right = Optional.ofNullable(error); | ||
} | ||
|
||
public static <U, E> Either<U, E> left(U value) { | ||
return new Either<>(value, null); | ||
} | ||
|
||
public static <U, E> Either<U, E> right(E error) { | ||
return new Either<>(null, error); | ||
} | ||
|
||
public boolean isRight() { | ||
return right.isPresent(); | ||
} | ||
|
||
public boolean isLeft() { | ||
return left.isPresent(); | ||
} | ||
|
||
public T get() throws RuntimeException { | ||
return unwrapLeft(); | ||
} | ||
|
||
public T unwrapLeft() throws RuntimeException { | ||
if (this.isRight()) | ||
throw new RuntimeException("Called unwrapLeft on an Right Either"); | ||
return left.get(); | ||
} | ||
|
||
public E unwrapRight() throws RuntimeException { | ||
if (this.isLeft()) | ||
throw new RuntimeException("Called UnwrapRight on an Left Either"); | ||
return right.get(); | ||
} | ||
|
||
} |