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

outcome

🌌outcome

outcome is a choice type that represents the result of a routine that
may either produce something useful or fail producing an error condition.

Several error conditions are needed if there are several very different
reasons for an operation to fail, e.g.

getData (u User, t Type) outcome<data, IOError, PermissionError> is
if u.allowedToAcces T
(readFile t.fileName)?
else
PermissionError u, t

readFile t Type outcome<data, IOError> is
[..]

Note that 'outcome<data, IOError>' is not assignment compatible with
'outcome<data, IOError, PermissionError>', it has to be unwrapped first.
This unwrapping, however, requires very little boilerplate, it is done
using the '?' on the result of the call to 'readFile': This unwraps
'outcome<data, IOError>' into 'IOError', which would be returned abruptly,
and 'data', which would be returned normally. Both are assignment
compatible to 'outcome<data, IOError, PermissionError>', so everything
is fine.

converts outcome to a string

returns the result of T.asString for a successful outcome, or
"--$e--" for e error.

redefines Object.asString:

error of an outcome that is known to contain an error

This can only be called in cases where it is known for sure that this
outcomee is an error. A runtime error will be created otherwise.

Does this outcome contain an error

Does this outcome contain a value of type T?

short-hand postfix operator for 'isError'

short-hand postfix operator for 'ok'

value of a outcome that is known to contain a value

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