-
Notifications
You must be signed in to change notification settings - Fork 16
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
Parallel Operation #16
Comments
Yes, I agree we should have these operations available. I have a gut feeling there's some sort of functional idiom for parallel processing that we can draw from. Maybe @Ostera can bring this to light, as he implemented a monad functor as a suggestion for bucklescript? |
@gilbert there isn't a particular algebra that models Future values, but if you want @dvisztempacct the behavior of module Future = {
type t('a);
let all: (list(t('a)), list('a) => 'b );
};
let sum_results_or_0_if_any_rejects =
[ Future.value(1), Future.value(2), Future.value(3) ]
|> Future.all( ~resolve = List.fold_left((+), 0), ~reject = 0))
/* would essentially be */
let f_1 = Future.value(1);
let f_2 = Future.value(2);
let f_3 = Future.value(3);
let all_3 =
f_1 |. Future.flatMap( first =>
f_2 |. Future.flatMap( second =>
/* at this stage below we have all the values, so we know if any rejections occurred */
/* let's assume they are all okay! */
f_3 |. Future.flatMap( third => Future.value([first, second, third ]))));
let sum_results_or_0_if_any_rejects =
all_3 |. Future.fold( ~reject = _ => 0, ~resolve = List.fold_left((+), 0)) Which can as well come from a similar functor, Traversable 💯 Unfortunately Hope this helps 🙏 |
Thanks for the input.
That's a good suggestion, thanks :) Please have a look at my PR #10 which implements a facility similar to https://github.com/RationalJS/future/pull/10/files Here is some code to test it:
I would add something like this to the |
I've addressed this in PR #18 |
So now there seems to be PR #22 offering the
requires a list of homogeneous items -> cannot be used when you want to wait different types of items. Therefore the |
They're not in the docs, but I discovered Future.map3(first, second, third, (a, b, c) => (a, b, c)) |
This library seems to be lacking idioms for parallel execution.
I'd like to see something like
Promise.all()
and additionally something like Bluebird'sPromise.join()
andPromise.map()
.The text was updated successfully, but these errors were encountered: