Skip to content

Latest commit

 

History

History
21 lines (15 loc) · 357 Bytes

optionals.md

File metadata and controls

21 lines (15 loc) · 357 Bytes

Optionals

Optional variable types are types that are allowed to contain a nil values:

foo: int? = 10
foo = nil
foo = 100

{% hint style="info" %} Optional types are denoted by a ? {% endhint %}

We can safely unwrap an optional value, given that it exists, using !like this:

foo: str? = maybe_a_str()
bar: str = foo!