harmony icon indicating copy to clipboard operation
harmony copied to clipboard

exists - then みたいなやつ

Open onihusube opened this issue 3 years ago • 2 comments

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版も必要。

求む適切な名前。

onihusube avatar Feb 22 '21 07:02 onihusube