|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objectorg.pocketgames.basic.Maybe<X>
X - any type that you want to store inside herepublic class Maybe<X>
This class represents something similar to the Haskell type Maybe. Note that part of the operations of that data type cannot be defined in Java at the current time.
Examples:
If you have a computation with a type that is optional, sometimes you might not want to use null to code the case in which that computation fails. In that case, your function can return.
Once you have your value, getting it back is quite easy. If the result of isNothing() is true, then your Maybe object holds nothing inside. If the result of isNothing is false, then fromJust should return that object inside the Maybe.
| Field Summary | |
|---|---|
static Maybe |
NOTHING
A default Nothing object. |
| Constructor Summary | |
|---|---|
Maybe(X val)
Default constructor for Just(Object). |
|
| Method Summary | |
|---|---|
X |
fromJust()
Obtains the value inside, reporting an exception if no value has been provided. |
boolean |
isJust()
Checks if this Maybe is not empty. |
boolean |
isNothing()
Checks if this Maybe is empty. |
X |
unsafeFromJust()
Obtains the value inside, without throwing any exception. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final Maybe NOTHING
| Constructor Detail |
|---|
public Maybe(X val)
val - a value to store inside.| Method Detail |
|---|
public boolean isNothing()
public boolean isJust()
public X unsafeFromJust()
public X fromJust()
throws java.lang.NoSuchFieldException
java.lang.NoSuchFieldException - if there's nothing inside
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||