support using co_await with folly::Optional when it is available
authorEric Niebler <eniebler@fb.com>
Fri, 8 Sep 2017 19:36:10 +0000 (12:36 -0700)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Fri, 8 Sep 2017 19:38:09 +0000 (12:38 -0700)
Summary:
Coroutines can be used to simulate the monadic "do" notion of Haskell. Use coroutines to enable monadic composition with folly::Optional.

```
Optional<int> f() {
  return 7;
}
Optional<int> g(int) {
  return folly::none;
}

void MonadicOptional() {
  Optional<int> r = []() -> Optional<int> {
    int x = co_await f();
    assert(x == 7);
    int y = co_await g(x);
    assert(false); // not executed
    co_return y;
  }();
  assert(!r.hasValue());
}
```

Reviewed By: yfeldblum

Differential Revision: D5763371

fbshipit-source-id: 9babc682244f38da7006d0b3a8444fd4efec1747


No differences found