13. Containers
Store multiple values together by using a container . Verse has a number of container types to store values in.
Option
The
option
type can contain one value or can be empty.In the following example,
MaybeANumber
is an optional integer?int
that contains no value, A new value forMaybeANumber
is then set to42
.
Initialization
You can initialize an option with one of the following:
No value: Assign
false
to the option to mark it as unset.Initial value: Use the keyword
option
followed by{}
, and an expression between the{}
. If the expression fails, the option will be unset and have the valuefalse
.Specify the type by adding
?
before the type of value expected to be stored in the option. For example?int
.
Last updated
Was this helpful?