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

Pipeline + Partial Application + await/yield #16

Closed
azz opened this issue Sep 30, 2017 · 6 comments
Closed

Pipeline + Partial Application + await/yield #16

azz opened this issue Sep 30, 2017 · 6 comments

Comments

@azz
Copy link

azz commented Sep 30, 2017

Context: tc39/proposal-pipeline-operator#53

Does it make sense to introduce a way to integrate the syntax of this proposal and the pipeline proposal in the case of async functions?

If it was legal to place await within a partially applied function when part of a pipeline, then:

const foo = await (1
  |> addOne(await?)
  |> double(await?)
);

would be loosely equivalent to:

const foo = await (1
  |> async x => await addOne(x)
  |> async x => await double(x)
);

which in turn is loosely:

const foo = (
  await double(
    await addOne(
      1
    )
  )
);

Syntax alternative:

const foo = 1
  |> await addOne(?)
  |> await double(?)
@gilbert
Copy link

gilbert commented Sep 30, 2017

I think with the current proposal semantics, it would be translated this way:

double(await ?)
//=>
double(x => await x)

...because the ? operator only applies to the immediately surrounding invocation (hence the motivation for #13).

@rbuckton
Copy link
Collaborator

rbuckton commented Oct 2, 2017

If partial application results in eager evaluation, I would need to add a special form for ? to allow await ? to work, but in that case the semantics are more like:

const foo = await (1
  |> (async x => addOne(await x))
  |> (async y => double(await y))
);

Another approach might be to have some syntax for an async pipeline, similar to for await, e.g.:

const foo = 1
  await |> addOne(?)
  await |> double(?);

@phaux
Copy link

phaux commented Oct 12, 2017

You can easily achieve the same thing without a special syntax:

const foo = await p
  .then(addOne(?))
  .then(double(?))

@azz
Copy link
Author

azz commented Oct 15, 2017

Wouldn't addOne(?) be the same as x => addOne(x) ?

@dead-claudia
Copy link

Yes, but the point is that with promises, it's moderately a moot point because we already have then.

@rbuckton
Copy link
Collaborator

Given that the pipeline proposal has moved forward with Hack-style, and the new syntax and semantics from #49, this is no longer an issue for partial application.

Since partial application is eager, f~(await p, ?) would perform the following steps:

  1. Evaluate f (we'll call that _f for the purpose of this algorithm)
  2. Evaluate p (as _p)
  3. Evaluate await _p (as _await_p)
  4. Produce a partially applied function for _f~(_await_p, ?)

The same would apply to yield.

I've added these along with desugaring examples to EXAMPLE.md in the repository root.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants