'Do' More with 'Run'
maxgreenwald.me
'Do' More with 'Run'
1–10 of 33 posts
Re: 'Do' More with 'Run'
#2 function doWork() {
const x = run(() => {
if (foo()) return f();
if (bar()) return g();
return h();
});
return x * 10;
}Re: 'Do' More with 'Run'
#3I am in love with “everything is an expression” from my time with Rust. I regularly use a ‘let’ and wish I could just have the entire conditional feed into a ‘const’ given it’s never going to change after the block of code responsible for assignment.
I wish there were more generations of ‘use strict’ so that we could make bolder, more breaking changes to the language without breaking stuff or dying in a horrible fire of “just roll your own dialect using compiler plugins.”
Re: 'Do' More with 'Run'
#4In the "Use as a `do` expression" section, the example which uses `run` does not need the `else` cases and could be simplified: function doWork() { const x = run(() => { if (foo()) return f(); if (bar()) return g(); return h(); }); return x * 10; }
function doWork() {
const x = () => {
if (foo()) return f();
if (bar()) return g();
return h();
};
return x() * 10;
}Re: 'Do' More with 'Run'
#5Re: 'Do' More with 'Run'
#6In the "Use as a `do` expression" section, the example which uses `run` does not need the `else` cases and could be simplified: function doWork() { const x = run(() => { if (foo()) return f(); if (bar()) return g(); return h(); }); return x * 10; }
Can also get rid of the `run` and move parens to simplify even further: function doWork() { const x = () => { if (foo()) return f(); if (bar()) return g(); return h(); }; return x() * 10; }
function doWork() {
function calcX() {
if (foo()) return f();
if (bar()) return g();
return h();
}
return calcX() * 10;
}
Where "calc" can be "gen[erate]" or "find" or at least more descriptive.Re: 'Do' More with 'Run'
#7Re: 'Do' More with 'Run'
#8Feels like code golf. The two run examples are basically the same, but now I have to reason about what ‘run’ is and I’ve made my stack trace more complicated. I am in love with “everything is an expression” from my time with Rust. I regularly use a ‘let’ and wish I could just have the entire conditional feed into a ‘const’ given it’s never going to change after the block of code responsible for assignment. I wish the…
Re: 'Do' More with 'Run'
#9In the "Use as a `do` expression" section, the example which uses `run` does not need the `else` cases and could be simplified: function doWork() { const x = run(() => { if (foo()) return f(); if (bar()) return g(); return h(); }); return x * 10; }
Can also get rid of the `run` and move parens to simplify even further: function doWork() { const x = () => { if (foo()) return f(); if (bar()) return g(); return h(); }; return x() * 10; }
Re: 'Do' More with 'Run'
#10 const wait = ms => new Promise(resolve => setTimeout(resolve, ms))
Whatever runs the main function should probably do more, like handling rejections.