Either type from Haskell?
So this is the crippled Java version of it (an explicit sum type).See: Description
| 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. |
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.