The "Pipeline" Operator - Making multiple function calls look great

Gilbert B Garza gilbertbgarza at gmail.com
Sat Dec 12 21:00:41 UTC 2015


`x |> f(y)` desugars to `f(y)(x)`

On Sat, Dec 12, 2015 at 2:55 PM, Isiah Meadows <isiahmeadows at gmail.com>
wrote:

> Question: does `x |> f(y)` desugar to `f(x, y)`, `f(y, x)`, or `f(y)(x)`?
>
> On Sat, Dec 12, 2015, 12:17 Gilbert B Garza <gilbertbgarza at gmail.com>
> wrote:
>
>> Ah yes, you are correct, it would need to be a special case as I wrote
>> it. This version should work instead:
>>
>> ```js
>> // Assume fs.readFile is an `async` function
>> async function runTask () {
>>   fs.readFile('./index.txt')
>>     |> await
>>     |> file => file
>>        .split('\n')
>>        .map(fs.readFile)
>>     |> Promise.all
>>     |> await
>>     |> all => all.join("\n")
>>     |> console.log
>> }
>> ```
>>
>> On Fri, Dec 11, 2015 at 7:08 PM, Kevin Smith <zenparsing at gmail.com>
>> wrote:
>>
>>> ```js
>>>> // Assume fs.readFile is an `async` function
>>>> async function runTask () {
>>>>   './index.txt'
>>>>     |> await fs.readFile
>>>>     |> file => file
>>>>        .split('\n')
>>>>        .map(fs.readFile)
>>>>     |> await Promise.all
>>>>     |> all => all.join("\n")
>>>>     |> console.log
>>>> }
>>>> ```
>>>>
>>>
>>> This doesn't work unless you special case the semantics of await
>>> expressions.  With the current semantics, `await fs.readFile` will just
>>> await `fs.readFile` not the result of applying it.
>>>
>>>
>> _______________________________________________
>> es-discuss mailing list
>> es-discuss at mozilla.org
>> https://mail.mozilla.org/listinfo/es-discuss
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20151212/40bb3829/attachment.html>


More information about the es-discuss mailing list