proxygen
set_done_2.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2018-present Facebook, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #include <algorithm>
17 #include <cassert>
18 #include <iostream>
19 #include <vector>
20 
26 
27 using namespace folly::pushmi::aliases;
28 
29 const bool setting_exists = false;
30 
31 auto get_setting() {
32  return mi::make_single_sender([](auto out) {
33  if (setting_exists) {
34  op::just(42) | op::submit(out);
35  } else {
36  op::empty<int>() | op::submit(out);
37  }
38  });
39 }
40 
41 auto println = [](auto v) { std::cout << v << std::endl; };
42 
43 // concat not yet implemented
44 template <class T, class E = std::exception_ptr>
45 auto concat = [](auto in) {
46  return mi::make_single_sender([in](auto out) mutable {
47  mi::submit(in, mi::make_receiver(out, [](auto out, auto v) {
49  }));
50  });
51 };
52 
53 int main() {
54  get_setting() | op::transform([](int i) { return std::to_string(i); }) |
56 
57  op::just(42) | op::filter([](int i) { return i < 42; }) |
58  op::transform([](int i) { return std::to_string(i); }) |
60 
61  op::just(42) | op::transform([](int i) {
62  if (i < 42) {
64  op::empty<std::string>()};
65  }
67  op::just(std::to_string(i))};
68  }) | concat<std::string> |
70 
71  std::cout << "OK" << std::endl;
72 }
auto v
PUSHMI_INLINE_VAR constexpr detail::filter_fn filter
Definition: filter.h:75
auto concat
Definition: set_done_2.cpp:45
int main()
Definition: set_done_2.cpp:53
PUSHMI_INLINE_VAR constexpr detail::transform_fn transform
Definition: transform.h:158
auto println
Definition: set_done_2.cpp:41
auto get_setting()
Definition: set_done_2.cpp:31
const bool setting_exists
Definition: set_done_2.cpp:29
PUSHMI_INLINE_VAR constexpr struct folly::pushmi::operators::just_fn just
PUSHMI_INLINE_VAR constexpr struct folly::pushmi::make_receiver_fn make_receiver
PUSHMI_INLINE_VAR constexpr struct folly::pushmi::make_single_sender_fn make_single_sender