Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

exists - then みたいなやつ #6

Open
onihusube opened this issue Feb 22, 2021 · 2 comments
Open

exists - then みたいなやつ #6

onihusube opened this issue Feb 22, 2021 · 2 comments
Labels
enhancement New feature or request

Comments

@onihusube
Copy link
Owner

onihusube commented Feb 22, 2021

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 onihusube added the enhancement New feature or request label Feb 22, 2021
@onihusube
Copy link
Owner Author

候補1 when().and_then(), when().or_else()

harmony::monas(f())
  | when([](int n) { return n == 20;}).and_then([](int n) { /* 何か処理 */ });

harmony::monas(f())
  | when([](int n) { return n == 20;}).or_else([](int n) { /* 何か処理 */ });

@onihusube
Copy link
Owner Author

onihusube commented Feb 23, 2021

harmony::monas(f())
  | when([](int n) { return n == 20;})
  | and_then([](int n) { /* 何か処理 */ });

の方が自然?

とするとfilterとかにした方がいい?

harmony::monas(f())
  | filter([](int n) { return n == 20;})
  | and_then([](int n) { /* 何か処理 */ });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant