outrun/outrun-core/lib/option.outrun

45 lines
996 B
Text

use Any
use Boolean
use Option
use Outrun.Core.Some, as: Some
use Outrun.Core.None, as: None
use LogicalNot
```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: do
```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: LogicalNot.not(Option.some?(option))
```doc
Create a new "some" value using the default some type.
```
def some(value: Any): Option, as: Some.new(value)
```doc
Create a new "none" value using the default none type.
```
def none(): Option, as: None.new()
end