Either type from Haskell?
So this is the crippled Java version of it (an explicit sum type).See: Description
| Interface | Description |
|---|---|
| BiFunction<A,B,C> | |
| EitherBiFunction<L,R1,B,R2> | |
| EitherConsumer<X> | |
| EitherFunction<L,R1,R2> | |
| Function<A,B> |
| Class | Description |
|---|---|
| Either<L,R> |
The
Either type (an explicit sum type for Java). |
| Either.Left<L,R> |
The
Left type. |
| Either.Right<L,R> |
The
Right type. |
| Eithers |
Static utility methods for dealing with
Either values. |
Do you know the Either type from Haskell?
So this is the crippled Java version of it (an explicit sum type).
final Either<String, Exception> value = Either.left("Hello World!");
if (value.isLeft()) {
System.out.println(value.getLeft());
}
}
-or
final Either<String, Exception> value = Either.left("Hello World!");
if (value instanceof Either.Left) {
System.out.println(value.getLeft());
}
}
Copyright © 2015. All rights reserved.