41 void MonadTest::testBoostOptionalReturn ()
43 const auto& pure = Return<boost::optional> (2);
44 QCOMPARE (pure, boost::optional<int> { 2 });
47 void MonadTest::testBoostOptionalBind ()
49 const auto& pure = Return<boost::optional> (2);
50 const auto& result =
Bind (pure, [] (
int value) {
return boost::optional<int> { ++value }; });
51 QCOMPARE (result, boost::optional<int> { 3 });
54 void MonadTest::testBoostOptionalBindEmpty ()
56 const auto& result =
Bind (boost::optional<int> {}, [] (
int value) {
return boost::optional<int> { ++value }; });
57 QCOMPARE (result, boost::optional<int> {});
60 void MonadTest::testBoostOptionalBindOperator ()
62 const auto& pure = Return<boost::optional> (2);
63 const auto& result = pure >> [] (
int value) {
return boost::optional<int> { ++value }; };
64 QCOMPARE (result, boost::optional<int> { 3 });
67 void MonadTest::testBoostOptionalBindEmptyOperator ()
69 const auto& result = boost::optional<int> {} >> [] (
int value) {
return boost::optional<int> { ++value }; };
70 QCOMPARE (result, boost::optional<int> {});
73 void MonadTest::testBoostOptionalDo ()
75 const auto& result =
Do (boost::optional<int> { 2 },
76 [] (
int a) -> boost::optional<int> {
return a * 2; },
77 [] (
int a) -> boost::optional<int> {
return a + 1; },
78 [] (
int a) -> boost::optional<int> {
return a * 3; });
79 QCOMPARE (result, boost::optional<int> { 15 });
82 void MonadTest::testBoostOptionalDoEmpty ()
85 const auto& result =
Do (boost::optional<int> { 2 },
86 [] (
int a) -> boost::optional<int> {
return a * 2; },
87 [] (int) -> boost::optional<int> {
return {}; },
88 [&called] (
int a) -> boost::optional<int> { called =
true;
return a * 3; });
90 QCOMPARE (result, boost::optional<int> {});
91 QCOMPARE (called,
false);
94 void MonadTest::testCompatibilitySingle ()
100 QCOMPARE (result,
true);
103 void MonadTest::testCompatibilitySingleDif ()
109 QCOMPARE (result,
true);
112 void MonadTest::testCompatibilityMulti ()
115 Typelist<int, float, QString>,
116 Typelist<int, float, QString>
118 QCOMPARE (result,
true);
121 void MonadTest::testCompatibilityMultiDifEnd ()
124 Typelist<int, float, QString>,
125 Typelist<int, float, QByteArray>
127 QCOMPARE (result,
true);
130 void MonadTest::testInCompatibilityMulti ()
133 Typelist<int, float, QString>,
134 Typelist<int, double, QString>
136 QCOMPARE (result,
false);
139 void MonadTest::testInCompatibilityMultiStart ()
142 Typelist<int, float, QString>,
143 Typelist<QByteArray, float, QString>
145 QCOMPARE (result,
false);
constexpr bool IsCompatibleMonad()
BindResult_t< MV, F > Bind(const MV &value, const F &f)