From d6f08efd55effe5fec01d5afbcb0412feea1a1f0 Mon Sep 17 00:00:00 2001 From: kayomn Date: Tue, 28 Feb 2023 14:08:14 +0000 Subject: [PATCH] Expose "and_then" on coral::expected --- source/coral.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/source/coral.cpp b/source/coral.cpp index ace6e29..fba2a8a 100755 --- a/source/coral.cpp +++ b/source/coral.cpp @@ -446,7 +446,7 @@ export namespace coral { template using rebound = expected; /** - * 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(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(this->buffer)) = error; } + /** + * Invokes the `apply` procedure if the expected is not ok, otherwise having no side-effects. + */ + void and_then(closure const & apply) { + if (this->is_ok()) apply(**this); + } + /** * Returns the contained error as an [optional]. */