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 'transform' operator that can be applied to various monad types #19

Closed
lewissbaker opened this issue Jun 19, 2017 · 4 comments
Closed
Assignees

Comments

@lewissbaker
Copy link
Owner

Support applying a function that transforms value of type A to value of type B to:

  • task<A> to produce task<B> (etc. for other task types)
  • generator<A> to prouduce generator<B> (etc. for other generator types)

Example syntax:

B a_to_b(const A& a);
cppcoro::task<A> make_an_a();

cppcoro::task<B> b = make_an_a() | cppcoro::transform(a_to_b);

For task<T> this is kind of similar to the proposed std::future<T>::then() method.

@lewissbaker
Copy link
Owner Author

Commits 1871e52 and fab674f add an fmap() operator for task, lazy_task and async_generator.

@lewissbaker
Copy link
Owner Author

One design question is whether to always return a unique task (task or lazy_task) even when the input is a shared_task or shared_lazy_task.

If we did then the caller would need to call make_shared_task to re-promote it to a shared task at cost of an extra coroutine frame allocation.

I expect that most use-cases will not need a shared task result, however, so returning a unique task is probably going to be more efficient.

@lewissbaker
Copy link
Owner Author

Still need to add fmap support for generator and recursive_generator.

A similar issue arises with fmap implementation for recursive_generator as to whether the result should be a recursive_generator or just a generator.

@lewissbaker lewissbaker self-assigned this Aug 17, 2017
@lewissbaker
Copy link
Owner Author

Commit 8e72893 adds fmap support for generator, recursive_generator and shared_task. It also adds docs to the README.

I've decided to go with following transformations when fmap is applied to specialisations of fundamental monad types:

  • recursive_generator -> generator
  • shared_task -> task

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