Is support for Applicative ("parallel") composition possible? #113
benhutchison
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
I'm seeing some real benefits to code clarity adopting the CPS style, primarily because it permits me to write expressions that refer to effectful values "in place", rather than having to pull them out front as named values (as both for-expr and flatMap chains demand).
Here's a real world example of a method written with flatMaps & mapN:
Using async/await, the code structure follows the natural structure of the output:
However.. The careful reader will note the use of Applicative composition in the first version, the
(fa, fb).mapN((a, b) => ...)pattern. The two fields ofGroupsAndModuleIdswe are building here are independent. We don't, but we could even build them in parallel, if resolving them were demanding enough to justify it.IIUC, we lose applicative composition in the CPS transform. All processing steps become sequential post-transform.
If "direct style" Scala via CPS-transform achieved widespread adoption and popularity, I expect gradually this would emerge as an issue. We would prefer not to accidentally introduce sequential dependencies between computations that are independent; this is a "loss of information".
Do we have any options for expressing applicative / "parallel" composition in a direct-style syntax?
All reactions