Expose "and_then" on coral::expected
This commit is contained in:
parent
d6f6bc246e
commit
d6f08efd55
@ -446,7 +446,7 @@ export namespace coral {
|
||||
template<typename value> using rebound = expected<value, errors>;
|
||||
|
||||
/**
|
||||
* Constructs from `value`, creating an [expected] that contains the expected type.
|
||||
* Constructs from `value`, creating an [expected] with the expected type.
|
||||
*/
|
||||
expected(expects const & value) {
|
||||
(*reinterpret_cast<expects *>(this->buffer)) = value;
|
||||
@ -454,12 +454,19 @@ export namespace coral {
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs from `error`, creating an [expected] that does not contain the expected type.
|
||||
* Constructs from `error`, creating an [expected] with an error.
|
||||
*/
|
||||
expected(errors const & error) {
|
||||
(*reinterpret_cast<errors *>(this->buffer)) = error;
|
||||
}
|
||||
|
||||
/**
|
||||
* Invokes the `apply` procedure if the expected is not ok, otherwise having no side-effects.
|
||||
*/
|
||||
void and_then(closure<void(expects &)> const & apply) {
|
||||
if (this->is_ok()) apply(**this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the contained error as an [optional].
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user