From 626eee7ef3ac15be9a0fd688150ceddd5e1977af Mon Sep 17 00:00:00 2001 From: TheNavigateur Date: Sun, 15 Oct 2017 09:06:40 +0530 Subject: [PATCH 1/7] Use of await and yield --- README.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/README.md b/README.md index 8a5c72d..fa23e84 100644 --- a/README.md +++ b/README.md @@ -86,6 +86,24 @@ newScore //=> 57 As you can see, because the pipe operator always pipes a single result value, it plays very nicely with the single-argument arrow function syntax. Also, because the pipe operator's semantics are pure and simple, it could be possible for JavaScript engines to optimize away the arrow function. +### Use of `await` and `yield` + +You can `await` in a function pipeline as follows: + +```js +const userAge = userId |> await fetchUserById |> getAgeFromUser +``` + +which would parsed identically to + +```js +const userAge = getAgeFromUser(await fetchUserById(userId)) +``` + +You can also `yield` and/or `yield await` in a function pipeline the same way. + +Basically, `|> await` / `|> yield` / `|> yield await` would be seen to be `await`ing or `yield`ing or `yield await`ing the result of the function with the argument supplied. + ### Usage with Function.prototype.papp If the [papp proposal](https://github.com/mindeavor/es-papp) gets accepted, the pipeline op would be even easier to use. Rewriting the previous example: From 10f275d77c832d78d4ca903c92f537773c733f59 Mon Sep 17 00:00:00 2001 From: TheNavigateur Date: Sun, 15 Oct 2017 09:25:32 +0530 Subject: [PATCH 2/7] Use of await and yield --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index fa23e84..cbe1754 100644 --- a/README.md +++ b/README.md @@ -102,7 +102,7 @@ const userAge = getAgeFromUser(await fetchUserById(userId)) You can also `yield` and/or `yield await` in a function pipeline the same way. -Basically, `|> await` / `|> yield` / `|> yield await` would be seen to be `await`ing or `yield`ing or `yield await`ing the result of the function with the argument supplied. +Basically, `|>` would glue with a higher precedence than `await` and `yield`, and `|> await` / `|> yield` / `|> yield await` would be seen to be `await`ing or `yield`ing or `yield await`ing the result of the function with the argument supplied. ### Usage with Function.prototype.papp From c22a6dfe34b03a37c608ecf0f504322e0ed04013 Mon Sep 17 00:00:00 2001 From: TheNavigateur Date: Sun, 15 Oct 2017 12:13:18 +0530 Subject: [PATCH 3/7] Use of await and yield --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index cbe1754..da99d02 100644 --- a/README.md +++ b/README.md @@ -94,7 +94,7 @@ You can `await` in a function pipeline as follows: const userAge = userId |> await fetchUserById |> getAgeFromUser ``` -which would parsed identically to +which would be parsed identically to ```js const userAge = getAgeFromUser(await fetchUserById(userId)) From 4bd61306a2162592f155e82588ab510244902285 Mon Sep 17 00:00:00 2001 From: TheNavigateur Date: Tue, 24 Oct 2017 10:06:40 +0530 Subject: [PATCH 4/7] Removed precedence comment from grammar description --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index da99d02..75f167d 100644 --- a/README.md +++ b/README.md @@ -102,7 +102,7 @@ const userAge = getAgeFromUser(await fetchUserById(userId)) You can also `yield` and/or `yield await` in a function pipeline the same way. -Basically, `|>` would glue with a higher precedence than `await` and `yield`, and `|> await` / `|> yield` / `|> yield await` would be seen to be `await`ing or `yield`ing or `yield await`ing the result of the function with the argument supplied. +Basically, `|> await` / `|> yield` / `|> yield await` would be seen to be `await`ing or `yield`ing or `yield await`ing the result of the function with the argument supplied. ### Usage with Function.prototype.papp From 24f9980e05342c4cc73c95e9e6cb1a2fa9ca3660 Mon Sep 17 00:00:00 2001 From: TheNavigateur Date: Fri, 27 Oct 2017 12:05:31 +0530 Subject: [PATCH 5/7] |> await |> form --- README.md | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 75f167d..ab76dfa 100644 --- a/README.md +++ b/README.md @@ -86,23 +86,31 @@ newScore //=> 57 As you can see, because the pipe operator always pipes a single result value, it plays very nicely with the single-argument arrow function syntax. Also, because the pipe operator's semantics are pure and simple, it could be possible for JavaScript engines to optimize away the arrow function. -### Use of `await` and `yield` +### Use of `await` -You can `await` in a function pipeline as follows: +The pipeline operator allows a `Promise` to be `await`ed as follows: ```js -const userAge = userId |> await fetchUserById |> getAgeFromUser +promise |> await ``` -which would be parsed identically to +which is the equivalent of ```js -const userAge = getAgeFromUser(await fetchUserById(userId)) +await promise +``` + +This is to allow you to `await` the result of an asynchronous function and pass it to the next function from within a function pipeline as follows: + +```js +const userAge = userId |> fetchUserById |> await |> getAgeFromUser ``` -You can also `yield` and/or `yield await` in a function pipeline the same way. +which is the equivalent of -Basically, `|> await` / `|> yield` / `|> yield await` would be seen to be `await`ing or `yield`ing or `yield await`ing the result of the function with the argument supplied. +```js +const userAge = getAgeFromUser(await fetchUserById(userId)) +``` ### Usage with Function.prototype.papp From fe02fd646e8b0e7d0efbe4d0182bfb403b4dfdd1 Mon Sep 17 00:00:00 2001 From: TheNavigateur Date: Fri, 27 Oct 2017 15:16:45 +0530 Subject: [PATCH 6/7] |> await |> form --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ab76dfa..b3d9b25 100644 --- a/README.md +++ b/README.md @@ -100,7 +100,7 @@ which is the equivalent of await promise ``` -This is to allow you to `await` the result of an asynchronous function and pass it to the next function from within a function pipeline as follows: +This is to allow you to `await` the result of an asynchronous function and pass it to the next function in a function pipeline, as follows: ```js const userAge = userId |> fetchUserById |> await |> getAgeFromUser From 436978c45d00767f49e1da10089303e64c4cf0e9 Mon Sep 17 00:00:00 2001 From: TheNavigateur Date: Fri, 27 Oct 2017 15:17:54 +0530 Subject: [PATCH 7/7] |> await |> form --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b3d9b25..5b8d296 100644 --- a/README.md +++ b/README.md @@ -100,7 +100,7 @@ which is the equivalent of await promise ``` -This is to allow you to `await` the result of an asynchronous function and pass it to the next function in a function pipeline, as follows: +This is to allow you to `await` the result of an asynchronous function and pass it to the next function from within a function pipeline, as follows: ```js const userAge = userId |> fetchUserById |> await |> getAgeFromUser