bulk.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #pragma once
  2. /*
  3. * Copyright 2018-present Facebook, Inc.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. #include <folly/experimental/pushmi/single_sender.h>
  18. namespace pushmi {
  19. namespace operators {
  20. PUSHMI_INLINE_VAR constexpr struct bulk_fn {
  21. template <
  22. class F,
  23. class ShapeBegin,
  24. class ShapeEnd,
  25. class Target,
  26. class IF,
  27. class RS>
  28. auto operator()(
  29. F&& func,
  30. ShapeBegin sb,
  31. ShapeEnd se,
  32. Target&& driver,
  33. IF&& initFunc,
  34. RS&& selector) const {
  35. return [func, sb, se, driver, initFunc, selector](auto in) {
  36. return make_single_sender(
  37. [in, func, sb, se, driver, initFunc, selector](auto out) mutable {
  38. submit(
  39. in,
  40. make_receiver(
  41. std::move(out),
  42. [func, sb, se, driver, initFunc, selector](
  43. auto& out, auto input) {
  44. driver(
  45. initFunc,
  46. selector,
  47. std::move(input),
  48. func,
  49. sb,
  50. se,
  51. std::move(out));
  52. }));
  53. });
  54. };
  55. }
  56. } bulk{};
  57. } // namespace operators
  58. } // namespace pushmi