Skip to content

compiler: syntactic sugar for combine #1396

@josephjclark

Description

@josephjclark

One thing that's very hard to do in job writing is do muliple steps in one.

each is the usual usecase, where I want to do:

each($.data, get, fn, post)

Where what I really want in the each is a little pipeline which processes each item through multiple operations

I can do this today with promises:

each($.data, get.then(fn).then(post))

But it's ugly, the compiler creaks, and error handling isn't great

You can also use combine, which is cool but no-one knows about it:

each($.data, combine(get(), fn(), post()))

I'm just wondering if we can do some syntactic sugar for combine, like:

each($.data, [get, fn, post])

But we probably can't distinguish this piping sort of expression from an array.

What if we used something more like piping?

each($.data, get |> fn |> post)
each($.data, get | fn | post)
each($.data, get > fn > post)
each($.data, @[get,fn , post])

Not terribly neat or intuitive.

using a pipe is OK but the synax isn't reserved, so how would I catch it?

JS does have a proposal for a pipeline operator: https://github.com/tc39/proposal-pipeline-operator

So it's this then:

each($.data, get |> fn |> post)

The compiler detects the chain and compiles it to:

each($.data, combine(get, fn, post))

You cannot use the pipe operator inside a block statement. Use it only in place of an operation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    New Issues

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions