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

Add 'bind' operator for task types #28

Open
lewissbaker opened this issue Aug 8, 2017 · 0 comments
Open

Add 'bind' operator for task types #28

lewissbaker opened this issue Aug 8, 2017 · 0 comments

Comments

@lewissbaker
Copy link
Owner

Basic usage:

cppcoro::task<A> makeA();
cppcoro::task<B> foo(A a);

cppcoro::task<B> b = makeA() | cpporo:bind(foo);
cppcoro::task<B> b2 = cppcoro::bind(foo, makeA());

Variadic usage:

cppcoro::task<A> makeA();
cppcoro::task<B> makeB();
cppcoro::task<C> func(A a, B b);

cppcoro::task<C> c = cppcoro::bind(func, makeA(), makeB());

Or alternatively, should this be done with an apply operator composed with bind and when_all?

cppcoro::task<C> c =
  cppcoro::when_all(makeA(), makeB())
  | cppcoro::bind(cppcoro::apply(func));

// Equivalent to
cppcoro::task<C> c = [](cppcoro::task<A> a, cppcoro::task<B> b) -> cppcoro::task<C>
{
  co_return co_await std::apply(func, co_await cppcoro::when_all(std::move(a), std::move(b)));
}(makeA(), makeB());
@lewissbaker lewissbaker changed the title Add 'bind' operator for monadic types Add 'bind' operator for task types Aug 8, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant