Live Cells C++
Reactive Programming for C++
Loading...
Searching...
No Matches
errors.hpp
1/*
2 * live_cells_cpp
3 * Copyright (C) 2024 Alexander Gutev <alex.gutev@gmail.com>
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License"); you
6 * may not use this file except in compliance with the License. You
7 * may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
14 * implied. See the License for the specific language governing
15 * permissions and limitations under the License.
16 */
17
18#ifndef LIVE_CELLS_ERRORS_HPP
19#define LIVE_CELLS_ERRORS_HPP
20
21#include "observable.hpp"
22#include "computed.hpp"
23#include "store_cell.hpp"
24
25namespace live_cells {
41 auto on_error(const Cell auto &cell, const Cell auto &error_value) {
42 return store(
43 make_compute_cell([=] () {
44 try {
45 return cell.value();
46 }
47 catch (...) {
48 return error_value.value();
49 }
50 }, cell, error_value)
51 );
52 }
53
72 template <typename E>
73 auto on_error(const Cell auto &cell, const Cell auto &error_value) {
74 return store(
75 make_compute_cell([=] () {
76 try {
77 return cell.value();
78 }
79 catch (const E &) {
80 return error_value.value();
81 }
82 }, cell, error_value)
83 );
84 }
85
86 namespace ops {
87
99 auto on_error(const Cell auto &error_value) {
100 return [&] (const Cell auto &cell) {
102 };
103 }
104
116 template <typename E>
117 auto on_error(const Cell auto &error_value) {
118 return [&] (const Cell auto &cell) {
120 };
121 }
122
123 } // operators
124
125} // live_cells
126
127#endif /* LIVE_CELLS_ERRORS_HPP */
Dynamically typed Cell container.
Definition observable.hpp:133
T value() const
Get the value held by the underlying Cell.
Definition observable.hpp:197
A computed cell which determines its argument cells at runtime.
Definition dynamic_compute_cell.hpp:153
Defines the cell protocol.
Definition types.hpp:128
auto on_error(const Cell auto &error_value)
Create an Operator for handling exceptions thrown by the operand Cell.
Definition errors.hpp:99
Definition boolean.hpp:26
auto store(const C &arg)
Create a Cell that caches the value of another Cell.
Definition store_cell.hpp:206
auto on_error(const Cell auto &cell, const Cell auto &error_value)
Create a Cell which handles all exceptions thrown while computing the value of a cell.
Definition errors.hpp:41
auto make_compute_cell(std::invocable auto f, auto... args)
Definition compute_cell.hpp:100