Fuzion Logo
fuzion-lang.dev — The Fuzion Language Portal
JavaScript seems to be disabled. Functionality is limited.

option

🌌option

option represents an optional value of type T

synonyme for infix >>=

converts option to a string

returns the result of $T for an option containing an instance
of T, alternatively returns $nil for an option that is nil.

redefines Object.asString:

monadic operator

Same as non-generic >>=, but also maps to a different type B.

Does this option contain a value of type T?

unwraps an option that is known to contain a value

this can only be called in cases where it is known for sure that this option
is not nil. A runtime error will be created otherwise.

§get(default T)
 => 
T
:
Object

unwraps an option if it exists, returns default value otherwise.

monadic operator

This is handy to implement functions on optional values. As an example,
take an option<string> and you would like to add a filename suffix to
this string if it is present. Then you can do this as follows:

addTxt(o option<string>) => o >>= s -> option<string> is s + ".txt"

NYI: With better type inference and syntactic sugar, this should be

addTxt(o option<string>) => o >>= s -> s + ".txt"

NYI: Should maybe have generic parameter <B> and result in option<B>

redefines monad.infix >>=:
monadic operator within the same monad

Apply f to elements of type A and re-wrap them in this monad.

Does this option contain no value of type T?

map this option using f, i.e., map nil to nil and any value v to f v

short-hand postfix operator for 'isNil'

short-hand postfix operator for 'exists'