Skip to content
Anton Zherdev edited this page May 22, 2014 · 1 revision

option ::= <datatype>?

You can use safe dot operation with this datatype and also all operation of the Option class. To check if the value is empty you have to compare it with nil.

stub class Option<T> {
    //Get the value or throw exception
    def get : T

    //Get the value if defined or return the parameter
    def getOr(value : T) : T

    //Return self if defined or the parameter
    def or(option : T?) : T?

    //Execute the lambda if defined
    def for(f : T -> void)

    //Return new option with mapped value or none
    def map<X>(f : T -> X) : X?

    //Return the option returned with the lambda or none
    def flatMap<X>(f : T -> X?) : X?
}
Clone this wiki locally