metasync icon indicating copy to clipboard operation
metasync copied to clipboard

Alternative syntax

Open tshemsedinov opened this issue 5 years ago • 8 comments

Syntax idea by @primeare, modifications by @tshemsedinov

const { μ } = require('metasync');
const f = μ(f1)(f2, μ(f3)(f4), f5)(f6);
f((err, result) => {
  console.dir(err, result);
});

Known problems:

  • How can we compose sequential inside parallel composition? Solved: μ(f3)(f4) in example.
  • We can't distinguish sequential composition and composed function call. So when we will start execution?

tshemsedinov avatar Sep 01 '18 22:09 tshemsedinov

I don't like the idea of using utf8 symbol you can't easily write from the keyboard and have to copy paste (μ). As for the syntax, I find just using arrays much clearer as to what's going on. This syntax is cluttered with parentheses that hide the actual meaning too much imo. Perhaps at least:

const { seq, par } = require('metasync');
const f = seq(f1, par(f2, seq(f3, f4), f5), f6);
f((err, result) => {
  console.dir(err, result);
});

lundibundi avatar Sep 02 '18 14:09 lundibundi

I saved proposal from @primeare here just for notes, @lundibundi We have no solution to distinguish sequential composition and composed function call, because f have a same contract with f6, so should we compose or start execution on next (). But maybe it will be used in future or will give inspiration to someone.

tshemsedinov avatar Sep 02 '18 18:09 tshemsedinov

@lundibundi I like arrays too, because it all other syntax will finally save calls to data structures (most likely those arrays) and then will iterate executing seq/par. Arrays are enough expressive so no need to build arrays implicitly.

tshemsedinov avatar Sep 02 '18 18:09 tshemsedinov

@lundibundi

I don't like the idea of using utf8 symbol you can't easily write from the keyboard and have to copy paste (μ).

FWIW, even if you don't setup AltGr or whatever it's called on your system (which you probably do, because you can't even enter em-dashes (—) from the keyboard otherwise; on Macs, for example, it is set up by default, so µ is just Option+m), you can enable Greek input method and enter µ as switch to Greek, m, switch back to English.

I agree that a non-ASCII name shouldn't be the only one for a function, but a convenient Unicode alias does sound like a good idea to me.

aqrln avatar Sep 03 '18 15:09 aqrln

Well, if it's an alias I'm fine. I don't want a unicode symbol to be the only way of accessing the function.

lundibundi avatar Sep 03 '18 16:09 lundibundi

@primeare why [2, 3] ? What does it mean? All returning from μ functions will have callback-last contract and all callbacks will have error-first.

tshemsedinov avatar Sep 09 '18 22:09 tshemsedinov

Do you mead μ(f1) will return single-argument function (callback) => () like this?

tshemsedinov avatar Sep 09 '18 22:09 tshemsedinov

@primeare please prepare PR so we can test it in CI and compare with current implementation syntactically and by performance.

tshemsedinov avatar Oct 01 '18 22:10 tshemsedinov