[HN Gopher] 'Do' More with 'Run' ___________________________________________________________________ 'Do' More with 'Run' Author : mgreenw Score : 7 points Date : 2023-05-19 14:06 UTC (8 hours ago) (HTM) web link (maxgreenwald.me) (TXT) w3m dump (maxgreenwald.me) | Waterluvian wrote: | Feels 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 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." | jlhawn wrote: | In 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; } | bestcoder69 wrote: | 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; } ___________________________________________________________________ (page generated 2023-05-19 23:00 UTC)