harmony
harmony copied to clipboard
exists - then みたいなやつ
monadicオブジェクトが有効値を持っていて、かつ指定された条件を満たした時、にand_then
するようなやつ。
auto f() -> expected<int, bool>;
// こんな雰囲気
harmony::monas(f())
| exists([](int n) { return n == 20;}).then([](int n) { /* 何か処理 */ });
// あるいは
harmony::monas(f())
| exists_then([](int n) { return n == 20;}, [](int n) { /* 何か処理 */ });
// and_thenでやろうとするとこうなる
harmony::monas(f())
| and_then(
[](int n) {
if (n == 20) {
/* 何か処理 */
} else {
return n;
}
});
双対的にor_else
版も必要。
求む適切な名前。