40 lines
898 B
Text
40 lines
898 B
Text
```doc
|
|
# Option
|
|
|
|
The optional type.
|
|
|
|
An option is anything that an optionally provide a value. Most commonly this will be in the shape of the `Outrun.Core.Option` enum.
|
|
```
|
|
|
|
protocol Option, as:
|
|
```doc
|
|
Returns true if the `Option` can provide a value, false otherwise.
|
|
|
|
Must be implemented.
|
|
```
|
|
def some?(option: Self): Boolean
|
|
|
|
```doc
|
|
Returns the value of the option, or raises an error if it can not.
|
|
|
|
Must be implemented.
|
|
```
|
|
def unwrap(option: Self): Any
|
|
|
|
```doc
|
|
Returns true if the `Option` cannot provide a value, false otherwise.
|
|
```
|
|
def none?(option: Self): Boolean, as:
|
|
!some?(option)
|
|
end
|
|
|
|
```doc
|
|
Create a new "some" value using the default some type.
|
|
```
|
|
defs some(value: Any): Option, as: Outrun.Core.Some.new(value)
|
|
|
|
```doc
|
|
Create a new "none" value using the default none type.
|
|
```
|
|
defs none(): Option, as: Outrun.Core.None.new()
|
|
end
|