From f43314cb53d9666f75e9dc09b01ae105ec09a6f4 Mon Sep 17 00:00:00 2001 From: kayomn Date: Mon, 27 Feb 2023 00:46:12 +0000 Subject: [PATCH] Reimplement coral::optional::and_then --- source/coral.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/source/coral.cpp b/source/coral.cpp index ad03759..ace6e29 100644 --- a/source/coral.cpp +++ b/source/coral.cpp @@ -382,6 +382,13 @@ export namespace coral { } } + /** + * Invokes the `apply` procedure if the optional is not empty, otherwise having no side-effects. + */ + void and_then(closure const & apply) { + if (this->has_value()) apply(**this); + } + /** * Returns `true` if the optional contains a value, otherwise `false`. */