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

Should FlatMap unwrap inputs? #97

Closed
rohanpm opened this issue Jan 3, 2019 · 1 comment
Closed

Should FlatMap unwrap inputs? #97

rohanpm opened this issue Jan 3, 2019 · 1 comment

Comments

@rohanpm
Copy link
Owner

rohanpm commented Jan 3, 2019

Let's say that you have a function which returns a future, and sometimes you want to call it directly, other times you want to chain it with some subsequent flat_map.

Currently, with_flat_map does not unwrap incoming futures to the map function. Should it?

Without this feature, for this scenario it's necessary to insert some extra with_flat_map just to unwrap futures produced by an earlier step, e.g.

  Executors.sync().\
    bind(some_async_fn). \
    with_flat_map(lambda f: f). \
    with_flat_map(do_something_async_with_result)
@rohanpm
Copy link
Owner Author

rohanpm commented Jan 4, 2019

I think there should be flat_bind(x) which has the same meaning as bind(x).with_flat_map(lambda f: f).

rohanpm added a commit that referenced this issue Jan 6, 2019
bors bot added a commit that referenced this issue Jan 6, 2019
105: Introduce flat_bind r=rohanpm a=rohanpm

Fixes #97

Co-authored-by: Rohan McGovern <rohan@mcgovern.id.au>
@bors bors bot closed this as completed in #105 Jan 6, 2019
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